<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html lang="en">

<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <title>LCOV - code analysis - /usr/include/google/protobuf/io/coded_stream.h</title>
  <link rel="stylesheet" type="text/css" href="../../../../../gcov.css">
</head>

<body>

  <table width="100%" border=0 cellspacing=0 cellpadding=0>
    <tr><td class="title">LCOV - code coverage report</td></tr>
    <tr><td class="ruler"><img src="../../../../../glass.png" width=3 height=3 alt=""></td></tr>

    <tr>
      <td width="100%">
        <table cellpadding=1 border=0 width="100%">
          <tr>
            <td width="10%" class="headerItem">Current view:</td>
            <td width="35%" class="headerValue"><a href="../../../../../index.html">top level</a> - <a href="index.html">usr/include/google/protobuf/io</a> - coded_stream.h<span style="font-size: 80%;"> (source / <a href="coded_stream.h.func-sort-c.html">functions</a>)</span></td>
            <td width="5%"></td>
            <td width="15%"></td>
            <td width="10%" class="headerCovTableHead">Hit</td>
            <td width="10%" class="headerCovTableHead">Total</td>
            <td width="15%" class="headerCovTableHead">Coverage</td>
          </tr>
          <tr>
            <td class="headerItem">Test:</td>
            <td class="headerValue">code analysis</td>
            <td></td>
            <td class="headerItem">Lines:</td>
            <td class="headerCovTableEntry">29</td>
            <td class="headerCovTableEntry">78</td>
            <td class="headerCovTableEntryLo">37.2 %</td>
          </tr>
          <tr>
            <td class="headerItem">Date:</td>
            <td class="headerValue">2020-09-11 22:50:33</td>
            <td></td>
            <td class="headerItem">Functions:</td>
            <td class="headerCovTableEntry">2</td>
            <td class="headerCovTableEntry">6</td>
            <td class="headerCovTableEntryLo">33.3 %</td>
          </tr>
          <tr>
            <td class="headerItem">Legend:</td>
            <td class="headerValueLeg">            Lines:
            <span class="coverLegendCov">hit</span>
            <span class="coverLegendNoCov">not hit</span>
</td>
            <td></td>
          </tr>
          <tr><td><img src="../../../../../glass.png" width=3 height=3 alt=""></td></tr>
        </table>
      </td>
    </tr>

    <tr><td class="ruler"><img src="../../../../../glass.png" width=3 height=3 alt=""></td></tr>
  </table>

  <table cellpadding=0 cellspacing=0 border=0>
    <tr>
      <td><br></td>
    </tr>
    <tr>
      <td>
<pre class="sourceHeading">          Line data    Source code</pre>
<pre class="source">
<a name="1"><span class="lineNum">       1 </span>            : // Protocol Buffers - Google's data interchange format</a>
<span class="lineNum">       2 </span>            : // Copyright 2008 Google Inc.  All rights reserved.
<span class="lineNum">       3 </span>            : // https://developers.google.com/protocol-buffers/
<span class="lineNum">       4 </span>            : //
<span class="lineNum">       5 </span>            : // Redistribution and use in source and binary forms, with or without
<span class="lineNum">       6 </span>            : // modification, are permitted provided that the following conditions are
<span class="lineNum">       7 </span>            : // met:
<span class="lineNum">       8 </span>            : //
<span class="lineNum">       9 </span>            : //     * Redistributions of source code must retain the above copyright
<span class="lineNum">      10 </span>            : // notice, this list of conditions and the following disclaimer.
<span class="lineNum">      11 </span>            : //     * Redistributions in binary form must reproduce the above
<span class="lineNum">      12 </span>            : // copyright notice, this list of conditions and the following disclaimer
<span class="lineNum">      13 </span>            : // in the documentation and/or other materials provided with the
<span class="lineNum">      14 </span>            : // distribution.
<span class="lineNum">      15 </span>            : //     * Neither the name of Google Inc. nor the names of its
<span class="lineNum">      16 </span>            : // contributors may be used to endorse or promote products derived from
<span class="lineNum">      17 </span>            : // this software without specific prior written permission.
<span class="lineNum">      18 </span>            : //
<span class="lineNum">      19 </span>            : // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
<span class="lineNum">      20 </span>            : // &quot;AS IS&quot; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
<span class="lineNum">      21 </span>            : // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
<span class="lineNum">      22 </span>            : // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
<span class="lineNum">      23 </span>            : // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
<span class="lineNum">      24 </span>            : // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
<span class="lineNum">      25 </span>            : // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
<span class="lineNum">      26 </span>            : // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
<span class="lineNum">      27 </span>            : // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
<span class="lineNum">      28 </span>            : // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
<span class="lineNum">      29 </span>            : // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
<span class="lineNum">      30 </span>            : 
<span class="lineNum">      31 </span>            : // Author: kenton@google.com (Kenton Varda)
<span class="lineNum">      32 </span>            : //  Based on original Protocol Buffers design by
<span class="lineNum">      33 </span>            : //  Sanjay Ghemawat, Jeff Dean, and others.
<span class="lineNum">      34 </span>            : //
<span class="lineNum">      35 </span>            : // This file contains the CodedInputStream and CodedOutputStream classes,
<span class="lineNum">      36 </span>            : // which wrap a ZeroCopyInputStream or ZeroCopyOutputStream, respectively,
<span class="lineNum">      37 </span>            : // and allow you to read or write individual pieces of data in various
<span class="lineNum">      38 </span>            : // formats.  In particular, these implement the varint encoding for
<span class="lineNum">      39 </span>            : // integers, a simple variable-length encoding in which smaller numbers
<span class="lineNum">      40 </span>            : // take fewer bytes.
<span class="lineNum">      41 </span>            : //
<span class="lineNum">      42 </span>            : // Typically these classes will only be used internally by the protocol
<span class="lineNum">      43 </span>            : // buffer library in order to encode and decode protocol buffers.  Clients
<span class="lineNum">      44 </span>            : // of the library only need to know about this class if they wish to write
<span class="lineNum">      45 </span>            : // custom message parsing or serialization procedures.
<span class="lineNum">      46 </span>            : //
<span class="lineNum">      47 </span>            : // CodedOutputStream example:
<span class="lineNum">      48 </span>            : //   // Write some data to &quot;myfile&quot;.  First we write a 4-byte &quot;magic number&quot;
<span class="lineNum">      49 </span>            : //   // to identify the file type, then write a length-delimited string.  The
<span class="lineNum">      50 </span>            : //   // string is composed of a varint giving the length followed by the raw
<span class="lineNum">      51 </span>            : //   // bytes.
<span class="lineNum">      52 </span>            : //   int fd = open(&quot;myfile&quot;, O_WRONLY);
<span class="lineNum">      53 </span>            : //   ZeroCopyOutputStream* raw_output = new FileOutputStream(fd);
<span class="lineNum">      54 </span>            : //   CodedOutputStream* coded_output = new CodedOutputStream(raw_output);
<span class="lineNum">      55 </span>            : //
<span class="lineNum">      56 </span>            : //   int magic_number = 1234;
<span class="lineNum">      57 </span>            : //   char text[] = &quot;Hello world!&quot;;
<span class="lineNum">      58 </span>            : //   coded_output-&gt;WriteLittleEndian32(magic_number);
<span class="lineNum">      59 </span>            : //   coded_output-&gt;WriteVarint32(strlen(text));
<span class="lineNum">      60 </span>            : //   coded_output-&gt;WriteRaw(text, strlen(text));
<span class="lineNum">      61 </span>            : //
<span class="lineNum">      62 </span>            : //   delete coded_output;
<span class="lineNum">      63 </span>            : //   delete raw_output;
<span class="lineNum">      64 </span>            : //   close(fd);
<span class="lineNum">      65 </span>            : //
<span class="lineNum">      66 </span>            : // CodedInputStream example:
<span class="lineNum">      67 </span>            : //   // Read a file created by the above code.
<span class="lineNum">      68 </span>            : //   int fd = open(&quot;myfile&quot;, O_RDONLY);
<span class="lineNum">      69 </span>            : //   ZeroCopyInputStream* raw_input = new FileInputStream(fd);
<span class="lineNum">      70 </span>            : //   CodedInputStream coded_input = new CodedInputStream(raw_input);
<span class="lineNum">      71 </span>            : //
<span class="lineNum">      72 </span>            : //   coded_input-&gt;ReadLittleEndian32(&amp;magic_number);
<span class="lineNum">      73 </span>            : //   if (magic_number != 1234) {
<span class="lineNum">      74 </span>            : //     cerr &lt;&lt; &quot;File not in expected format.&quot; &lt;&lt; endl;
<span class="lineNum">      75 </span>            : //     return;
<span class="lineNum">      76 </span>            : //   }
<span class="lineNum">      77 </span>            : //
<span class="lineNum">      78 </span>            : //   uint32 size;
<span class="lineNum">      79 </span>            : //   coded_input-&gt;ReadVarint32(&amp;size);
<span class="lineNum">      80 </span>            : //
<span class="lineNum">      81 </span>            : //   char* text = new char[size + 1];
<span class="lineNum">      82 </span>            : //   coded_input-&gt;ReadRaw(buffer, size);
<span class="lineNum">      83 </span>            : //   text[size] = '\0';
<span class="lineNum">      84 </span>            : //
<span class="lineNum">      85 </span>            : //   delete coded_input;
<span class="lineNum">      86 </span>            : //   delete raw_input;
<span class="lineNum">      87 </span>            : //   close(fd);
<span class="lineNum">      88 </span>            : //
<span class="lineNum">      89 </span>            : //   cout &lt;&lt; &quot;Text is: &quot; &lt;&lt; text &lt;&lt; endl;
<span class="lineNum">      90 </span>            : //   delete [] text;
<span class="lineNum">      91 </span>            : //
<span class="lineNum">      92 </span>            : // For those who are interested, varint encoding is defined as follows:
<span class="lineNum">      93 </span>            : //
<span class="lineNum">      94 </span>            : // The encoding operates on unsigned integers of up to 64 bits in length.
<span class="lineNum">      95 </span>            : // Each byte of the encoded value has the format:
<span class="lineNum">      96 </span>            : // * bits 0-6: Seven bits of the number being encoded.
<span class="lineNum">      97 </span>            : // * bit 7: Zero if this is the last byte in the encoding (in which
<span class="lineNum">      98 </span>            : //   case all remaining bits of the number are zero) or 1 if
<span class="lineNum">      99 </span>            : //   more bytes follow.
<span class="lineNum">     100 </span>            : // The first byte contains the least-significant 7 bits of the number, the
<span class="lineNum">     101 </span>            : // second byte (if present) contains the next-least-significant 7 bits,
<span class="lineNum">     102 </span>            : // and so on.  So, the binary number 1011000101011 would be encoded in two
<span class="lineNum">     103 </span>            : // bytes as &quot;10101011 00101100&quot;.
<span class="lineNum">     104 </span>            : //
<span class="lineNum">     105 </span>            : // In theory, varint could be used to encode integers of any length.
<span class="lineNum">     106 </span>            : // However, for practicality we set a limit at 64 bits.  The maximum encoded
<span class="lineNum">     107 </span>            : // length of a number is thus 10 bytes.
<span class="lineNum">     108 </span>            : 
<span class="lineNum">     109 </span>            : #ifndef GOOGLE_PROTOBUF_IO_CODED_STREAM_H__
<span class="lineNum">     110 </span>            : #define GOOGLE_PROTOBUF_IO_CODED_STREAM_H__
<span class="lineNum">     111 </span>            : 
<span class="lineNum">     112 </span>            : #include &lt;string&gt;
<span class="lineNum">     113 </span>            : #ifdef _MSC_VER
<span class="lineNum">     114 </span>            :   #if defined(_M_IX86) &amp;&amp; \
<span class="lineNum">     115 </span>            :       !defined(PROTOBUF_DISABLE_LITTLE_ENDIAN_OPT_FOR_TEST)
<span class="lineNum">     116 </span>            :     #define PROTOBUF_LITTLE_ENDIAN 1
<span class="lineNum">     117 </span>            :   #endif
<span class="lineNum">     118 </span>            :   #if _MSC_VER &gt;= 1300
<span class="lineNum">     119 </span>            :     // If MSVC has &quot;/RTCc&quot; set, it will complain about truncating casts at
<span class="lineNum">     120 </span>            :     // runtime.  This file contains some intentional truncating casts.
<span class="lineNum">     121 </span>            :     #pragma runtime_checks(&quot;c&quot;, off)
<span class="lineNum">     122 </span>            :   #endif
<span class="lineNum">     123 </span>            : #else
<span class="lineNum">     124 </span>            :   #include &lt;sys/param.h&gt;   // __BYTE_ORDER
<span class="lineNum">     125 </span>            :   #if defined(__BYTE_ORDER) &amp;&amp; __BYTE_ORDER == __LITTLE_ENDIAN &amp;&amp; \
<span class="lineNum">     126 </span>            :       !defined(PROTOBUF_DISABLE_LITTLE_ENDIAN_OPT_FOR_TEST)
<span class="lineNum">     127 </span>            :     #define PROTOBUF_LITTLE_ENDIAN 1
<span class="lineNum">     128 </span>            :   #endif
<span class="lineNum">     129 </span>            : #endif
<span class="lineNum">     130 </span>            : #include &lt;google/protobuf/stubs/common.h&gt;
<span class="lineNum">     131 </span>            : 
<span class="lineNum">     132 </span>            : 
<span class="lineNum">     133 </span>            : namespace google {
<span class="lineNum">     134 </span>            : namespace protobuf {
<span class="lineNum">     135 </span>            : 
<span class="lineNum">     136 </span>            : class DescriptorPool;
<span class="lineNum">     137 </span>            : class MessageFactory;
<span class="lineNum">     138 </span>            : 
<span class="lineNum">     139 </span>            : namespace io {
<span class="lineNum">     140 </span>            : 
<span class="lineNum">     141 </span>            : // Defined in this file.
<span class="lineNum">     142 </span>            : class CodedInputStream;
<span class="lineNum">     143 </span>            : class CodedOutputStream;
<span class="lineNum">     144 </span>            : 
<span class="lineNum">     145 </span>            : // Defined in other files.
<span class="lineNum">     146 </span>            : class ZeroCopyInputStream;           // zero_copy_stream.h
<span class="lineNum">     147 </span>            : class ZeroCopyOutputStream;          // zero_copy_stream.h
<span class="lineNum">     148 </span>            : 
<span class="lineNum">     149 </span>            : // Class which reads and decodes binary data which is composed of varint-
<span class="lineNum">     150 </span>            : // encoded integers and fixed-width pieces.  Wraps a ZeroCopyInputStream.
<span class="lineNum">     151 </span>            : // Most users will not need to deal with CodedInputStream.
<span class="lineNum">     152 </span>            : //
<span class="lineNum">     153 </span>            : // Most methods of CodedInputStream that return a bool return false if an
<span class="lineNum">     154 </span>            : // underlying I/O error occurs or if the data is malformed.  Once such a
<span class="lineNum">     155 </span>            : // failure occurs, the CodedInputStream is broken and is no longer useful.
<span class="lineNum">     156 </span>            : class LIBPROTOBUF_EXPORT CodedInputStream {
<span class="lineNum">     157 </span>            :  public:
<span class="lineNum">     158 </span>            :   // Create a CodedInputStream that reads from the given ZeroCopyInputStream.
<span class="lineNum">     159 </span>            :   explicit CodedInputStream(ZeroCopyInputStream* input);
<span class="lineNum">     160 </span>            : 
<span class="lineNum">     161 </span>            :   // Create a CodedInputStream that reads from the given flat array.  This is
<span class="lineNum">     162 </span>            :   // faster than using an ArrayInputStream.  PushLimit(size) is implied by
<span class="lineNum">     163 </span>            :   // this constructor.
<span class="lineNum">     164 </span>            :   explicit CodedInputStream(const uint8* buffer, int size);
<span class="lineNum">     165 </span>            : 
<span class="lineNum">     166 </span>            :   // Destroy the CodedInputStream and position the underlying
<span class="lineNum">     167 </span>            :   // ZeroCopyInputStream at the first unread byte.  If an error occurred while
<span class="lineNum">     168 </span>            :   // reading (causing a method to return false), then the exact position of
<span class="lineNum">     169 </span>            :   // the input stream may be anywhere between the last value that was read
<span class="lineNum">     170 </span>            :   // successfully and the stream's byte limit.
<span class="lineNum">     171 </span>            :   ~CodedInputStream();
<span class="lineNum">     172 </span>            : 
<span class="lineNum">     173 </span>            :   // Return true if this CodedInputStream reads from a flat array instead of
<span class="lineNum">     174 </span>            :   // a ZeroCopyInputStream.
<span class="lineNum">     175 </span>            :   inline bool IsFlat() const;
<span class="lineNum">     176 </span>            : 
<span class="lineNum">     177 </span>            :   // Skips a number of bytes.  Returns false if an underlying read error
<span class="lineNum">     178 </span>            :   // occurs.
<span class="lineNum">     179 </span>            :   bool Skip(int count);
<span class="lineNum">     180 </span>            : 
<span class="lineNum">     181 </span>            :   // Sets *data to point directly at the unread part of the CodedInputStream's
<span class="lineNum">     182 </span>            :   // underlying buffer, and *size to the size of that buffer, but does not
<span class="lineNum">     183 </span>            :   // advance the stream's current position.  This will always either produce
<span class="lineNum">     184 </span>            :   // a non-empty buffer or return false.  If the caller consumes any of
<span class="lineNum">     185 </span>            :   // this data, it should then call Skip() to skip over the consumed bytes.
<span class="lineNum">     186 </span>            :   // This may be useful for implementing external fast parsing routines for
<span class="lineNum">     187 </span>            :   // types of data not covered by the CodedInputStream interface.
<span class="lineNum">     188 </span>            :   bool GetDirectBufferPointer(const void** data, int* size);
<span class="lineNum">     189 </span>            : 
<span class="lineNum">     190 </span>            :   // Like GetDirectBufferPointer, but this method is inlined, and does not
<span class="lineNum">     191 </span>            :   // attempt to Refresh() if the buffer is currently empty.
<span class="lineNum">     192 </span>            :   inline void GetDirectBufferPointerInline(const void** data,
<span class="lineNum">     193 </span>            :                                            int* size) GOOGLE_ATTRIBUTE_ALWAYS_INLINE;
<span class="lineNum">     194 </span>            : 
<span class="lineNum">     195 </span>            :   // Read raw bytes, copying them into the given buffer.
<span class="lineNum">     196 </span>            :   bool ReadRaw(void* buffer, int size);
<span class="lineNum">     197 </span>            : 
<span class="lineNum">     198 </span>            :   // Like ReadRaw, but reads into a string.
<span class="lineNum">     199 </span>            :   //
<span class="lineNum">     200 </span>            :   // Implementation Note:  ReadString() grows the string gradually as it
<span class="lineNum">     201 </span>            :   // reads in the data, rather than allocating the entire requested size
<span class="lineNum">     202 </span>            :   // upfront.  This prevents denial-of-service attacks in which a client
<span class="lineNum">     203 </span>            :   // could claim that a string is going to be MAX_INT bytes long in order to
<span class="lineNum">     204 </span>            :   // crash the server because it can't allocate this much space at once.
<span class="lineNum">     205 </span>            :   bool ReadString(string* buffer, int size);
<span class="lineNum">     206 </span>            :   // Like the above, with inlined optimizations. This should only be used
<span class="lineNum">     207 </span>            :   // by the protobuf implementation.
<span class="lineNum">     208 </span>            :   inline bool InternalReadStringInline(string* buffer,
<span class="lineNum">     209 </span>            :                                        int size) GOOGLE_ATTRIBUTE_ALWAYS_INLINE;
<span class="lineNum">     210 </span>            : 
<span class="lineNum">     211 </span>            : 
<span class="lineNum">     212 </span>            :   // Read a 32-bit little-endian integer.
<span class="lineNum">     213 </span>            :   bool ReadLittleEndian32(uint32* value);
<span class="lineNum">     214 </span>            :   // Read a 64-bit little-endian integer.
<span class="lineNum">     215 </span>            :   bool ReadLittleEndian64(uint64* value);
<span class="lineNum">     216 </span>            : 
<span class="lineNum">     217 </span>            :   // These methods read from an externally provided buffer. The caller is
<span class="lineNum">     218 </span>            :   // responsible for ensuring that the buffer has sufficient space.
<span class="lineNum">     219 </span>            :   // Read a 32-bit little-endian integer.
<span class="lineNum">     220 </span>            :   static const uint8* ReadLittleEndian32FromArray(const uint8* buffer,
<span class="lineNum">     221 </span>            :                                                    uint32* value);
<span class="lineNum">     222 </span>            :   // Read a 64-bit little-endian integer.
<span class="lineNum">     223 </span>            :   static const uint8* ReadLittleEndian64FromArray(const uint8* buffer,
<span class="lineNum">     224 </span>            :                                                    uint64* value);
<span class="lineNum">     225 </span>            : 
<span class="lineNum">     226 </span>            :   // Read an unsigned integer with Varint encoding, truncating to 32 bits.
<span class="lineNum">     227 </span>            :   // Reading a 32-bit value is equivalent to reading a 64-bit one and casting
<span class="lineNum">     228 </span>            :   // it to uint32, but may be more efficient.
<span class="lineNum">     229 </span>            :   bool ReadVarint32(uint32* value);
<span class="lineNum">     230 </span>            :   // Read an unsigned integer with Varint encoding.
<span class="lineNum">     231 </span>            :   bool ReadVarint64(uint64* value);
<span class="lineNum">     232 </span>            : 
<span class="lineNum">     233 </span>            :   // Read a tag.  This calls ReadVarint32() and returns the result, or returns
<span class="lineNum">     234 </span>            :   // zero (which is not a valid tag) if ReadVarint32() fails.  Also, it updates
<span class="lineNum">     235 </span>            :   // the last tag value, which can be checked with LastTagWas().
<span class="lineNum">     236 </span>            :   // Always inline because this is only called in one place per parse loop
<span class="lineNum">     237 </span>            :   // but it is called for every iteration of said loop, so it should be fast.
<span class="lineNum">     238 </span>            :   // GCC doesn't want to inline this by default.
<span class="lineNum">     239 </span>            :   uint32 ReadTag() GOOGLE_ATTRIBUTE_ALWAYS_INLINE;
<span class="lineNum">     240 </span>            : 
<span class="lineNum">     241 </span>            :   // This usually a faster alternative to ReadTag() when cutoff is a manifest
<span class="lineNum">     242 </span>            :   // constant.  It does particularly well for cutoff &gt;= 127.  The first part
<span class="lineNum">     243 </span>            :   // of the return value is the tag that was read, though it can also be 0 in
<span class="lineNum">     244 </span>            :   // the cases where ReadTag() would return 0.  If the second part is true
<span class="lineNum">     245 </span>            :   // then the tag is known to be in [0, cutoff].  If not, the tag either is
<span class="lineNum">     246 </span>            :   // above cutoff or is 0.  (There's intentional wiggle room when tag is 0,
<span class="lineNum">     247 </span>            :   // because that can arise in several ways, and for best performance we want
<span class="lineNum">     248 </span>            :   // to avoid an extra &quot;is tag == 0?&quot; check here.)
<span class="lineNum">     249 </span>            :   inline std::pair&lt;uint32, bool&gt; ReadTagWithCutoff(uint32 cutoff)
<span class="lineNum">     250 </span>            :       GOOGLE_ATTRIBUTE_ALWAYS_INLINE;
<span class="lineNum">     251 </span>            : 
<span class="lineNum">     252 </span>            :   // Usually returns true if calling ReadVarint32() now would produce the given
<span class="lineNum">     253 </span>            :   // value.  Will always return false if ReadVarint32() would not return the
<span class="lineNum">     254 </span>            :   // given value.  If ExpectTag() returns true, it also advances past
<span class="lineNum">     255 </span>            :   // the varint.  For best performance, use a compile-time constant as the
<span class="lineNum">     256 </span>            :   // parameter.
<span class="lineNum">     257 </span>            :   // Always inline because this collapses to a small number of instructions
<span class="lineNum">     258 </span>            :   // when given a constant parameter, but GCC doesn't want to inline by default.
<span class="lineNum">     259 </span>            :   bool ExpectTag(uint32 expected) GOOGLE_ATTRIBUTE_ALWAYS_INLINE;
<span class="lineNum">     260 </span>            : 
<span class="lineNum">     261 </span>            :   // Like above, except this reads from the specified buffer. The caller is
<span class="lineNum">     262 </span>            :   // responsible for ensuring that the buffer is large enough to read a varint
<span class="lineNum">     263 </span>            :   // of the expected size. For best performance, use a compile-time constant as
<span class="lineNum">     264 </span>            :   // the expected tag parameter.
<span class="lineNum">     265 </span>            :   //
<span class="lineNum">     266 </span>            :   // Returns a pointer beyond the expected tag if it was found, or NULL if it
<span class="lineNum">     267 </span>            :   // was not.
<span class="lineNum">     268 </span>            :   static const uint8* ExpectTagFromArray(
<span class="lineNum">     269 </span>            :       const uint8* buffer,
<span class="lineNum">     270 </span>            :       uint32 expected) GOOGLE_ATTRIBUTE_ALWAYS_INLINE;
<span class="lineNum">     271 </span>            : 
<span class="lineNum">     272 </span>            :   // Usually returns true if no more bytes can be read.  Always returns false
<span class="lineNum">     273 </span>            :   // if more bytes can be read.  If ExpectAtEnd() returns true, a subsequent
<span class="lineNum">     274 </span>            :   // call to LastTagWas() will act as if ReadTag() had been called and returned
<span class="lineNum">     275 </span>            :   // zero, and ConsumedEntireMessage() will return true.
<span class="lineNum">     276 </span>            :   bool ExpectAtEnd();
<span class="lineNum">     277 </span>            : 
<span class="lineNum">     278 </span>            :   // If the last call to ReadTag() or ReadTagWithCutoff() returned the
<span class="lineNum">     279 </span>            :   // given value, returns true.  Otherwise, returns false;
<span class="lineNum">     280 </span>            :   //
<span class="lineNum">     281 </span>            :   // This is needed because parsers for some types of embedded messages
<span class="lineNum">     282 </span>            :   // (with field type TYPE_GROUP) don't actually know that they've reached the
<span class="lineNum">     283 </span>            :   // end of a message until they see an ENDGROUP tag, which was actually part
<span class="lineNum">     284 </span>            :   // of the enclosing message.  The enclosing message would like to check that
<span class="lineNum">     285 </span>            :   // tag to make sure it had the right number, so it calls LastTagWas() on
<span class="lineNum">     286 </span>            :   // return from the embedded parser to check.
<span class="lineNum">     287 </span>            :   bool LastTagWas(uint32 expected);
<span class="lineNum">     288 </span>            : 
<span class="lineNum">     289 </span>            :   // When parsing message (but NOT a group), this method must be called
<span class="lineNum">     290 </span>            :   // immediately after MergeFromCodedStream() returns (if it returns true)
<span class="lineNum">     291 </span>            :   // to further verify that the message ended in a legitimate way.  For
<span class="lineNum">     292 </span>            :   // example, this verifies that parsing did not end on an end-group tag.
<span class="lineNum">     293 </span>            :   // It also checks for some cases where, due to optimizations,
<span class="lineNum">     294 </span>            :   // MergeFromCodedStream() can incorrectly return true.
<span class="lineNum">     295 </span>            :   bool ConsumedEntireMessage();
<span class="lineNum">     296 </span>            : 
<span class="lineNum">     297 </span>            :   // Limits ----------------------------------------------------------
<span class="lineNum">     298 </span>            :   // Limits are used when parsing length-delimited embedded messages.
<span class="lineNum">     299 </span>            :   // After the message's length is read, PushLimit() is used to prevent
<span class="lineNum">     300 </span>            :   // the CodedInputStream from reading beyond that length.  Once the
<span class="lineNum">     301 </span>            :   // embedded message has been parsed, PopLimit() is called to undo the
<span class="lineNum">     302 </span>            :   // limit.
<span class="lineNum">     303 </span>            : 
<span class="lineNum">     304 </span>            :   // Opaque type used with PushLimit() and PopLimit().  Do not modify
<span class="lineNum">     305 </span>            :   // values of this type yourself.  The only reason that this isn't a
<span class="lineNum">     306 </span>            :   // struct with private internals is for efficiency.
<span class="lineNum">     307 </span>            :   typedef int Limit;
<span class="lineNum">     308 </span>            : 
<span class="lineNum">     309 </span>            :   // Places a limit on the number of bytes that the stream may read,
<span class="lineNum">     310 </span>            :   // starting from the current position.  Once the stream hits this limit,
<span class="lineNum">     311 </span>            :   // it will act like the end of the input has been reached until PopLimit()
<span class="lineNum">     312 </span>            :   // is called.
<span class="lineNum">     313 </span>            :   //
<span class="lineNum">     314 </span>            :   // As the names imply, the stream conceptually has a stack of limits.  The
<span class="lineNum">     315 </span>            :   // shortest limit on the stack is always enforced, even if it is not the
<span class="lineNum">     316 </span>            :   // top limit.
<span class="lineNum">     317 </span>            :   //
<span class="lineNum">     318 </span>            :   // The value returned by PushLimit() is opaque to the caller, and must
<span class="lineNum">     319 </span>            :   // be passed unchanged to the corresponding call to PopLimit().
<span class="lineNum">     320 </span>            :   Limit PushLimit(int byte_limit);
<span class="lineNum">     321 </span>            : 
<span class="lineNum">     322 </span>            :   // Pops the last limit pushed by PushLimit().  The input must be the value
<span class="lineNum">     323 </span>            :   // returned by that call to PushLimit().
<span class="lineNum">     324 </span>            :   void PopLimit(Limit limit);
<span class="lineNum">     325 </span>            : 
<span class="lineNum">     326 </span>            :   // Returns the number of bytes left until the nearest limit on the
<span class="lineNum">     327 </span>            :   // stack is hit, or -1 if no limits are in place.
<span class="lineNum">     328 </span>            :   int BytesUntilLimit() const;
<span class="lineNum">     329 </span>            : 
<span class="lineNum">     330 </span>            :   // Returns current position relative to the beginning of the input stream.
<span class="lineNum">     331 </span>            :   int CurrentPosition() const;
<span class="lineNum">     332 </span>            : 
<span class="lineNum">     333 </span>            :   // Total Bytes Limit -----------------------------------------------
<span class="lineNum">     334 </span>            :   // To prevent malicious users from sending excessively large messages
<span class="lineNum">     335 </span>            :   // and causing integer overflows or memory exhaustion, CodedInputStream
<span class="lineNum">     336 </span>            :   // imposes a hard limit on the total number of bytes it will read.
<span class="lineNum">     337 </span>            : 
<span class="lineNum">     338 </span>            :   // Sets the maximum number of bytes that this CodedInputStream will read
<span class="lineNum">     339 </span>            :   // before refusing to continue.  To prevent integer overflows in the
<span class="lineNum">     340 </span>            :   // protocol buffers implementation, as well as to prevent servers from
<span class="lineNum">     341 </span>            :   // allocating enormous amounts of memory to hold parsed messages, the
<span class="lineNum">     342 </span>            :   // maximum message length should be limited to the shortest length that
<span class="lineNum">     343 </span>            :   // will not harm usability.  The theoretical shortest message that could
<span class="lineNum">     344 </span>            :   // cause integer overflows is 512MB.  The default limit is 64MB.  Apps
<span class="lineNum">     345 </span>            :   // should set shorter limits if possible.  If warning_threshold is not -1,
<span class="lineNum">     346 </span>            :   // a warning will be printed to stderr after warning_threshold bytes are
<span class="lineNum">     347 </span>            :   // read.  For backwards compatibility all negative values get squashed to -1,
<span class="lineNum">     348 </span>            :   // as other negative values might have special internal meanings.
<span class="lineNum">     349 </span>            :   // An error will always be printed to stderr if the limit is reached.
<span class="lineNum">     350 </span>            :   //
<span class="lineNum">     351 </span>            :   // This is unrelated to PushLimit()/PopLimit().
<span class="lineNum">     352 </span>            :   //
<span class="lineNum">     353 </span>            :   // Hint:  If you are reading this because your program is printing a
<span class="lineNum">     354 </span>            :   //   warning about dangerously large protocol messages, you may be
<span class="lineNum">     355 </span>            :   //   confused about what to do next.  The best option is to change your
<span class="lineNum">     356 </span>            :   //   design such that excessively large messages are not necessary.
<span class="lineNum">     357 </span>            :   //   For example, try to design file formats to consist of many small
<span class="lineNum">     358 </span>            :   //   messages rather than a single large one.  If this is infeasible,
<span class="lineNum">     359 </span>            :   //   you will need to increase the limit.  Chances are, though, that
<span class="lineNum">     360 </span>            :   //   your code never constructs a CodedInputStream on which the limit
<span class="lineNum">     361 </span>            :   //   can be set.  You probably parse messages by calling things like
<span class="lineNum">     362 </span>            :   //   Message::ParseFromString().  In this case, you will need to change
<span class="lineNum">     363 </span>            :   //   your code to instead construct some sort of ZeroCopyInputStream
<span class="lineNum">     364 </span>            :   //   (e.g. an ArrayInputStream), construct a CodedInputStream around
<span class="lineNum">     365 </span>            :   //   that, then call Message::ParseFromCodedStream() instead.  Then
<span class="lineNum">     366 </span>            :   //   you can adjust the limit.  Yes, it's more work, but you're doing
<span class="lineNum">     367 </span>            :   //   something unusual.
<span class="lineNum">     368 </span>            :   void SetTotalBytesLimit(int total_bytes_limit, int warning_threshold);
<span class="lineNum">     369 </span>            : 
<span class="lineNum">     370 </span>            :   // The Total Bytes Limit minus the Current Position, or -1 if there
<span class="lineNum">     371 </span>            :   // is no Total Bytes Limit.
<span class="lineNum">     372 </span>            :   int BytesUntilTotalBytesLimit() const;
<span class="lineNum">     373 </span>            : 
<span class="lineNum">     374 </span>            :   // Recursion Limit -------------------------------------------------
<span class="lineNum">     375 </span>            :   // To prevent corrupt or malicious messages from causing stack overflows,
<span class="lineNum">     376 </span>            :   // we must keep track of the depth of recursion when parsing embedded
<span class="lineNum">     377 </span>            :   // messages and groups.  CodedInputStream keeps track of this because it
<span class="lineNum">     378 </span>            :   // is the only object that is passed down the stack during parsing.
<span class="lineNum">     379 </span>            : 
<span class="lineNum">     380 </span>            :   // Sets the maximum recursion depth.  The default is 100.
<span class="lineNum">     381 </span>            :   void SetRecursionLimit(int limit);
<span class="lineNum">     382 </span>            : 
<span class="lineNum">     383 </span>            : 
<span class="lineNum">     384 </span>            :   // Increments the current recursion depth.  Returns true if the depth is
<span class="lineNum">     385 </span>            :   // under the limit, false if it has gone over.
<span class="lineNum">     386 </span>            :   bool IncrementRecursionDepth();
<span class="lineNum">     387 </span>            : 
<span class="lineNum">     388 </span>            :   // Decrements the recursion depth.
<span class="lineNum">     389 </span>            :   void DecrementRecursionDepth();
<span class="lineNum">     390 </span>            : 
<span class="lineNum">     391 </span>            :   // Extension Registry ----------------------------------------------
<span class="lineNum">     392 </span>            :   // ADVANCED USAGE:  99.9% of people can ignore this section.
<span class="lineNum">     393 </span>            :   //
<span class="lineNum">     394 </span>            :   // By default, when parsing extensions, the parser looks for extension
<span class="lineNum">     395 </span>            :   // definitions in the pool which owns the outer message's Descriptor.
<span class="lineNum">     396 </span>            :   // However, you may call SetExtensionRegistry() to provide an alternative
<span class="lineNum">     397 </span>            :   // pool instead.  This makes it possible, for example, to parse a message
<span class="lineNum">     398 </span>            :   // using a generated class, but represent some extensions using
<span class="lineNum">     399 </span>            :   // DynamicMessage.
<span class="lineNum">     400 </span>            : 
<span class="lineNum">     401 </span>            :   // Set the pool used to look up extensions.  Most users do not need to call
<span class="lineNum">     402 </span>            :   // this as the correct pool will be chosen automatically.
<span class="lineNum">     403 </span>            :   //
<span class="lineNum">     404 </span>            :   // WARNING:  It is very easy to misuse this.  Carefully read the requirements
<span class="lineNum">     405 </span>            :   //   below.  Do not use this unless you are sure you need it.  Almost no one
<span class="lineNum">     406 </span>            :   //   does.
<span class="lineNum">     407 </span>            :   //
<span class="lineNum">     408 </span>            :   // Let's say you are parsing a message into message object m, and you want
<span class="lineNum">     409 </span>            :   // to take advantage of SetExtensionRegistry().  You must follow these
<span class="lineNum">     410 </span>            :   // requirements:
<span class="lineNum">     411 </span>            :   //
<span class="lineNum">     412 </span>            :   // The given DescriptorPool must contain m-&gt;GetDescriptor().  It is not
<span class="lineNum">     413 </span>            :   // sufficient for it to simply contain a descriptor that has the same name
<span class="lineNum">     414 </span>            :   // and content -- it must be the *exact object*.  In other words:
<span class="lineNum">     415 </span>            :   //   assert(pool-&gt;FindMessageTypeByName(m-&gt;GetDescriptor()-&gt;full_name()) ==
<span class="lineNum">     416 </span>            :   //          m-&gt;GetDescriptor());
<span class="lineNum">     417 </span>            :   // There are two ways to satisfy this requirement:
<span class="lineNum">     418 </span>            :   // 1) Use m-&gt;GetDescriptor()-&gt;pool() as the pool.  This is generally useless
<span class="lineNum">     419 </span>            :   //    because this is the pool that would be used anyway if you didn't call
<span class="lineNum">     420 </span>            :   //    SetExtensionRegistry() at all.
<span class="lineNum">     421 </span>            :   // 2) Use a DescriptorPool which has m-&gt;GetDescriptor()-&gt;pool() as an
<span class="lineNum">     422 </span>            :   //    &quot;underlay&quot;.  Read the documentation for DescriptorPool for more
<span class="lineNum">     423 </span>            :   //    information about underlays.
<span class="lineNum">     424 </span>            :   //
<span class="lineNum">     425 </span>            :   // You must also provide a MessageFactory.  This factory will be used to
<span class="lineNum">     426 </span>            :   // construct Message objects representing extensions.  The factory's
<span class="lineNum">     427 </span>            :   // GetPrototype() MUST return non-NULL for any Descriptor which can be found
<span class="lineNum">     428 </span>            :   // through the provided pool.
<span class="lineNum">     429 </span>            :   //
<span class="lineNum">     430 </span>            :   // If the provided factory might return instances of protocol-compiler-
<span class="lineNum">     431 </span>            :   // generated (i.e. compiled-in) types, or if the outer message object m is
<span class="lineNum">     432 </span>            :   // a generated type, then the given factory MUST have this property:  If
<span class="lineNum">     433 </span>            :   // GetPrototype() is given a Descriptor which resides in
<span class="lineNum">     434 </span>            :   // DescriptorPool::generated_pool(), the factory MUST return the same
<span class="lineNum">     435 </span>            :   // prototype which MessageFactory::generated_factory() would return.  That
<span class="lineNum">     436 </span>            :   // is, given a descriptor for a generated type, the factory must return an
<span class="lineNum">     437 </span>            :   // instance of the generated class (NOT DynamicMessage).  However, when
<span class="lineNum">     438 </span>            :   // given a descriptor for a type that is NOT in generated_pool, the factory
<span class="lineNum">     439 </span>            :   // is free to return any implementation.
<span class="lineNum">     440 </span>            :   //
<span class="lineNum">     441 </span>            :   // The reason for this requirement is that generated sub-objects may be
<span class="lineNum">     442 </span>            :   // accessed via the standard (non-reflection) extension accessor methods,
<span class="lineNum">     443 </span>            :   // and these methods will down-cast the object to the generated class type.
<span class="lineNum">     444 </span>            :   // If the object is not actually of that type, the results would be undefined.
<span class="lineNum">     445 </span>            :   // On the other hand, if an extension is not compiled in, then there is no
<span class="lineNum">     446 </span>            :   // way the code could end up accessing it via the standard accessors -- the
<span class="lineNum">     447 </span>            :   // only way to access the extension is via reflection.  When using reflection,
<span class="lineNum">     448 </span>            :   // DynamicMessage and generated messages are indistinguishable, so it's fine
<span class="lineNum">     449 </span>            :   // if these objects are represented using DynamicMessage.
<span class="lineNum">     450 </span>            :   //
<span class="lineNum">     451 </span>            :   // Using DynamicMessageFactory on which you have called
<span class="lineNum">     452 </span>            :   // SetDelegateToGeneratedFactory(true) should be sufficient to satisfy the
<span class="lineNum">     453 </span>            :   // above requirement.
<span class="lineNum">     454 </span>            :   //
<span class="lineNum">     455 </span>            :   // If either pool or factory is NULL, both must be NULL.
<span class="lineNum">     456 </span>            :   //
<span class="lineNum">     457 </span>            :   // Note that this feature is ignored when parsing &quot;lite&quot; messages as they do
<span class="lineNum">     458 </span>            :   // not have descriptors.
<span class="lineNum">     459 </span>            :   void SetExtensionRegistry(const DescriptorPool* pool,
<span class="lineNum">     460 </span>            :                             MessageFactory* factory);
<span class="lineNum">     461 </span>            : 
<span class="lineNum">     462 </span>            :   // Get the DescriptorPool set via SetExtensionRegistry(), or NULL if no pool
<span class="lineNum">     463 </span>            :   // has been provided.
<span class="lineNum">     464 </span>            :   const DescriptorPool* GetExtensionPool();
<span class="lineNum">     465 </span>            : 
<span class="lineNum">     466 </span>            :   // Get the MessageFactory set via SetExtensionRegistry(), or NULL if no
<span class="lineNum">     467 </span>            :   // factory has been provided.
<span class="lineNum">     468 </span>            :   MessageFactory* GetExtensionFactory();
<span class="lineNum">     469 </span>            : 
<span class="lineNum">     470 </span>            :  private:
<span class="lineNum">     471 </span>            :   GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(CodedInputStream);
<span class="lineNum">     472 </span>            : 
<span class="lineNum">     473 </span>            :   ZeroCopyInputStream* input_;
<span class="lineNum">     474 </span>            :   const uint8* buffer_;
<span class="lineNum">     475 </span>            :   const uint8* buffer_end_;     // pointer to the end of the buffer.
<span class="lineNum">     476 </span>            :   int total_bytes_read_;  // total bytes read from input_, including
<span class="lineNum">     477 </span>            :                           // the current buffer
<span class="lineNum">     478 </span>            : 
<span class="lineNum">     479 </span>            :   // If total_bytes_read_ surpasses INT_MAX, we record the extra bytes here
<span class="lineNum">     480 </span>            :   // so that we can BackUp() on destruction.
<span class="lineNum">     481 </span>            :   int overflow_bytes_;
<span class="lineNum">     482 </span>            : 
<span class="lineNum">     483 </span>            :   // LastTagWas() stuff.
<span class="lineNum">     484 </span>            :   uint32 last_tag_;         // result of last ReadTag() or ReadTagWithCutoff().
<span class="lineNum">     485 </span>            : 
<span class="lineNum">     486 </span>            :   // This is set true by ReadTag{Fallback/Slow}() if it is called when exactly
<span class="lineNum">     487 </span>            :   // at EOF, or by ExpectAtEnd() when it returns true.  This happens when we
<span class="lineNum">     488 </span>            :   // reach the end of a message and attempt to read another tag.
<span class="lineNum">     489 </span>            :   bool legitimate_message_end_;
<span class="lineNum">     490 </span>            : 
<span class="lineNum">     491 </span>            :   // See EnableAliasing().
<span class="lineNum">     492 </span>            :   bool aliasing_enabled_;
<span class="lineNum">     493 </span>            : 
<span class="lineNum">     494 </span>            :   // Limits
<span class="lineNum">     495 </span>            :   Limit current_limit_;   // if position = -1, no limit is applied
<span class="lineNum">     496 </span>            : 
<span class="lineNum">     497 </span>            :   // For simplicity, if the current buffer crosses a limit (either a normal
<span class="lineNum">     498 </span>            :   // limit created by PushLimit() or the total bytes limit), buffer_size_
<span class="lineNum">     499 </span>            :   // only tracks the number of bytes before that limit.  This field
<span class="lineNum">     500 </span>            :   // contains the number of bytes after it.  Note that this implies that if
<span class="lineNum">     501 </span>            :   // buffer_size_ == 0 and buffer_size_after_limit_ &gt; 0, we know we've
<span class="lineNum">     502 </span>            :   // hit a limit.  However, if both are zero, it doesn't necessarily mean
<span class="lineNum">     503 </span>            :   // we aren't at a limit -- the buffer may have ended exactly at the limit.
<span class="lineNum">     504 </span>            :   int buffer_size_after_limit_;
<span class="lineNum">     505 </span>            : 
<span class="lineNum">     506 </span>            :   // Maximum number of bytes to read, period.  This is unrelated to
<span class="lineNum">     507 </span>            :   // current_limit_.  Set using SetTotalBytesLimit().
<span class="lineNum">     508 </span>            :   int total_bytes_limit_;
<span class="lineNum">     509 </span>            : 
<span class="lineNum">     510 </span>            :   // If positive/0: Limit for bytes read after which a warning due to size
<span class="lineNum">     511 </span>            :   // should be logged.
<span class="lineNum">     512 </span>            :   // If -1: Printing of warning disabled. Can be set by client.
<span class="lineNum">     513 </span>            :   // If -2: Internal: Limit has been reached, print full size when destructing.
<span class="lineNum">     514 </span>            :   int total_bytes_warning_threshold_;
<span class="lineNum">     515 </span>            : 
<span class="lineNum">     516 </span>            :   // Current recursion depth, controlled by IncrementRecursionDepth() and
<span class="lineNum">     517 </span>            :   // DecrementRecursionDepth().
<span class="lineNum">     518 </span>            :   int recursion_depth_;
<span class="lineNum">     519 </span>            :   // Recursion depth limit, set by SetRecursionLimit().
<span class="lineNum">     520 </span>            :   int recursion_limit_;
<span class="lineNum">     521 </span>            : 
<span class="lineNum">     522 </span>            :   // See SetExtensionRegistry().
<span class="lineNum">     523 </span>            :   const DescriptorPool* extension_pool_;
<span class="lineNum">     524 </span>            :   MessageFactory* extension_factory_;
<span class="lineNum">     525 </span>            : 
<span class="lineNum">     526 </span>            :   // Private member functions.
<span class="lineNum">     527 </span>            : 
<span class="lineNum">     528 </span>            :   // Advance the buffer by a given number of bytes.
<span class="lineNum">     529 </span>            :   void Advance(int amount);
<span class="lineNum">     530 </span>            : 
<span class="lineNum">     531 </span>            :   // Back up input_ to the current buffer position.
<span class="lineNum">     532 </span>            :   void BackUpInputToCurrentPosition();
<span class="lineNum">     533 </span>            : 
<span class="lineNum">     534 </span>            :   // Recomputes the value of buffer_size_after_limit_.  Must be called after
<span class="lineNum">     535 </span>            :   // current_limit_ or total_bytes_limit_ changes.
<span class="lineNum">     536 </span>            :   void RecomputeBufferLimits();
<span class="lineNum">     537 </span>            : 
<span class="lineNum">     538 </span>            :   // Writes an error message saying that we hit total_bytes_limit_.
<span class="lineNum">     539 </span>            :   void PrintTotalBytesLimitError();
<span class="lineNum">     540 </span>            : 
<span class="lineNum">     541 </span>            :   // Called when the buffer runs out to request more data.  Implies an
<span class="lineNum">     542 </span>            :   // Advance(BufferSize()).
<span class="lineNum">     543 </span>            :   bool Refresh();
<span class="lineNum">     544 </span>            : 
<span class="lineNum">     545 </span>            :   // When parsing varints, we optimize for the common case of small values, and
<span class="lineNum">     546 </span>            :   // then optimize for the case when the varint fits within the current buffer
<span class="lineNum">     547 </span>            :   // piece. The Fallback method is used when we can't use the one-byte
<span class="lineNum">     548 </span>            :   // optimization. The Slow method is yet another fallback when the buffer is
<span class="lineNum">     549 </span>            :   // not large enough. Making the slow path out-of-line speeds up the common
<span class="lineNum">     550 </span>            :   // case by 10-15%. The slow path is fairly uncommon: it only triggers when a
<span class="lineNum">     551 </span>            :   // message crosses multiple buffers.
<span class="lineNum">     552 </span>            :   bool ReadVarint32Fallback(uint32* value);
<span class="lineNum">     553 </span>            :   bool ReadVarint64Fallback(uint64* value);
<span class="lineNum">     554 </span>            :   bool ReadVarint32Slow(uint32* value);
<span class="lineNum">     555 </span>            :   bool ReadVarint64Slow(uint64* value);
<span class="lineNum">     556 </span>            :   bool ReadLittleEndian32Fallback(uint32* value);
<span class="lineNum">     557 </span>            :   bool ReadLittleEndian64Fallback(uint64* value);
<span class="lineNum">     558 </span>            :   // Fallback/slow methods for reading tags. These do not update last_tag_,
<span class="lineNum">     559 </span>            :   // but will set legitimate_message_end_ if we are at the end of the input
<span class="lineNum">     560 </span>            :   // stream.
<span class="lineNum">     561 </span>            :   uint32 ReadTagFallback();
<span class="lineNum">     562 </span>            :   uint32 ReadTagSlow();
<span class="lineNum">     563 </span>            :   bool ReadStringFallback(string* buffer, int size);
<span class="lineNum">     564 </span>            : 
<span class="lineNum">     565 </span>            :   // Return the size of the buffer.
<span class="lineNum">     566 </span>            :   int BufferSize() const;
<span class="lineNum">     567 </span>            : 
<span class="lineNum">     568 </span>            :   static const int kDefaultTotalBytesLimit = 64 &lt;&lt; 20;  // 64MB
<span class="lineNum">     569 </span>            : 
<span class="lineNum">     570 </span>            :   static const int kDefaultTotalBytesWarningThreshold = 32 &lt;&lt; 20;  // 32MB
<span class="lineNum">     571 </span>            : 
<span class="lineNum">     572 </span>            :   static int default_recursion_limit_;  // 100 by default.
<span class="lineNum">     573 </span>            : };
<span class="lineNum">     574 </span>            : 
<span class="lineNum">     575 </span>            : // Class which encodes and writes binary data which is composed of varint-
<span class="lineNum">     576 </span>            : // encoded integers and fixed-width pieces.  Wraps a ZeroCopyOutputStream.
<span class="lineNum">     577 </span>            : // Most users will not need to deal with CodedOutputStream.
<span class="lineNum">     578 </span>            : //
<span class="lineNum">     579 </span>            : // Most methods of CodedOutputStream which return a bool return false if an
<span class="lineNum">     580 </span>            : // underlying I/O error occurs.  Once such a failure occurs, the
<span class="lineNum">     581 </span>            : // CodedOutputStream is broken and is no longer useful. The Write* methods do
<span class="lineNum">     582 </span>            : // not return the stream status, but will invalidate the stream if an error
<span class="lineNum">     583 </span>            : // occurs. The client can probe HadError() to determine the status.
<span class="lineNum">     584 </span>            : //
<span class="lineNum">     585 </span>            : // Note that every method of CodedOutputStream which writes some data has
<span class="lineNum">     586 </span>            : // a corresponding static &quot;ToArray&quot; version. These versions write directly
<span class="lineNum">     587 </span>            : // to the provided buffer, returning a pointer past the last written byte.
<span class="lineNum">     588 </span>            : // They require that the buffer has sufficient capacity for the encoded data.
<span class="lineNum">     589 </span>            : // This allows an optimization where we check if an output stream has enough
<span class="lineNum">     590 </span>            : // space for an entire message before we start writing and, if there is, we
<span class="lineNum">     591 </span>            : // call only the ToArray methods to avoid doing bound checks for each
<span class="lineNum">     592 </span>            : // individual value.
<span class="lineNum">     593 </span>            : // i.e., in the example above:
<span class="lineNum">     594 </span>            : //
<span class="lineNum">     595 </span>            : //   CodedOutputStream coded_output = new CodedOutputStream(raw_output);
<span class="lineNum">     596 </span>            : //   int magic_number = 1234;
<span class="lineNum">     597 </span>            : //   char text[] = &quot;Hello world!&quot;;
<span class="lineNum">     598 </span>            : //
<span class="lineNum">     599 </span>            : //   int coded_size = sizeof(magic_number) +
<span class="lineNum">     600 </span>            : //                    CodedOutputStream::VarintSize32(strlen(text)) +
<span class="lineNum">     601 </span>            : //                    strlen(text);
<span class="lineNum">     602 </span>            : //
<span class="lineNum">     603 </span>            : //   uint8* buffer =
<span class="lineNum">     604 </span>            : //       coded_output-&gt;GetDirectBufferForNBytesAndAdvance(coded_size);
<span class="lineNum">     605 </span>            : //   if (buffer != NULL) {
<span class="lineNum">     606 </span>            : //     // The output stream has enough space in the buffer: write directly to
<span class="lineNum">     607 </span>            : //     // the array.
<span class="lineNum">     608 </span>            : //     buffer = CodedOutputStream::WriteLittleEndian32ToArray(magic_number,
<span class="lineNum">     609 </span>            : //                                                            buffer);
<span class="lineNum">     610 </span>            : //     buffer = CodedOutputStream::WriteVarint32ToArray(strlen(text), buffer);
<span class="lineNum">     611 </span>            : //     buffer = CodedOutputStream::WriteRawToArray(text, strlen(text), buffer);
<span class="lineNum">     612 </span>            : //   } else {
<span class="lineNum">     613 </span>            : //     // Make bound-checked writes, which will ask the underlying stream for
<span class="lineNum">     614 </span>            : //     // more space as needed.
<span class="lineNum">     615 </span>            : //     coded_output-&gt;WriteLittleEndian32(magic_number);
<span class="lineNum">     616 </span>            : //     coded_output-&gt;WriteVarint32(strlen(text));
<span class="lineNum">     617 </span>            : //     coded_output-&gt;WriteRaw(text, strlen(text));
<span class="lineNum">     618 </span>            : //   }
<span class="lineNum">     619 </span>            : //
<span class="lineNum">     620 </span>            : //   delete coded_output;
<span class="lineNum">     621 </span>            : class LIBPROTOBUF_EXPORT CodedOutputStream {
<span class="lineNum">     622 </span>            :  public:
<span class="lineNum">     623 </span>            :   // Create an CodedOutputStream that writes to the given ZeroCopyOutputStream.
<span class="lineNum">     624 </span>            :   explicit CodedOutputStream(ZeroCopyOutputStream* output);
<span class="lineNum">     625 </span>            : 
<span class="lineNum">     626 </span>            :   // Destroy the CodedOutputStream and position the underlying
<span class="lineNum">     627 </span>            :   // ZeroCopyOutputStream immediately after the last byte written.
<span class="lineNum">     628 </span>            :   ~CodedOutputStream();
<span class="lineNum">     629 </span>            : 
<span class="lineNum">     630 </span>            :   // Skips a number of bytes, leaving the bytes unmodified in the underlying
<span class="lineNum">     631 </span>            :   // buffer.  Returns false if an underlying write error occurs.  This is
<span class="lineNum">     632 </span>            :   // mainly useful with GetDirectBufferPointer().
<span class="lineNum">     633 </span>            :   bool Skip(int count);
<span class="lineNum">     634 </span>            : 
<span class="lineNum">     635 </span>            :   // Sets *data to point directly at the unwritten part of the
<span class="lineNum">     636 </span>            :   // CodedOutputStream's underlying buffer, and *size to the size of that
<span class="lineNum">     637 </span>            :   // buffer, but does not advance the stream's current position.  This will
<span class="lineNum">     638 </span>            :   // always either produce a non-empty buffer or return false.  If the caller
<span class="lineNum">     639 </span>            :   // writes any data to this buffer, it should then call Skip() to skip over
<span class="lineNum">     640 </span>            :   // the consumed bytes.  This may be useful for implementing external fast
<span class="lineNum">     641 </span>            :   // serialization routines for types of data not covered by the
<span class="lineNum">     642 </span>            :   // CodedOutputStream interface.
<span class="lineNum">     643 </span>            :   bool GetDirectBufferPointer(void** data, int* size);
<span class="lineNum">     644 </span>            : 
<span class="lineNum">     645 </span>            :   // If there are at least &quot;size&quot; bytes available in the current buffer,
<span class="lineNum">     646 </span>            :   // returns a pointer directly into the buffer and advances over these bytes.
<span class="lineNum">     647 </span>            :   // The caller may then write directly into this buffer (e.g. using the
<span class="lineNum">     648 </span>            :   // *ToArray static methods) rather than go through CodedOutputStream.  If
<span class="lineNum">     649 </span>            :   // there are not enough bytes available, returns NULL.  The return pointer is
<span class="lineNum">     650 </span>            :   // invalidated as soon as any other non-const method of CodedOutputStream
<span class="lineNum">     651 </span>            :   // is called.
<span class="lineNum">     652 </span>            :   inline uint8* GetDirectBufferForNBytesAndAdvance(int size);
<span class="lineNum">     653 </span>            : 
<span class="lineNum">     654 </span>            :   // Write raw bytes, copying them from the given buffer.
<span class="lineNum">     655 </span>            :   void WriteRaw(const void* buffer, int size);
<span class="lineNum">     656 </span>            :   // Like WriteRaw()  but will try to write aliased data if aliasing is
<span class="lineNum">     657 </span>            :   // turned on.
<span class="lineNum">     658 </span>            :   void WriteRawMaybeAliased(const void* data, int size);
<span class="lineNum">     659 </span>            :   // Like WriteRaw()  but writing directly to the target array.
<span class="lineNum">     660 </span>            :   // This is _not_ inlined, as the compiler often optimizes memcpy into inline
<span class="lineNum">     661 </span>            :   // copy loops. Since this gets called by every field with string or bytes
<span class="lineNum">     662 </span>            :   // type, inlining may lead to a significant amount of code bloat, with only a
<span class="lineNum">     663 </span>            :   // minor performance gain.
<span class="lineNum">     664 </span>            :   static uint8* WriteRawToArray(const void* buffer, int size, uint8* target);
<span class="lineNum">     665 </span>            : 
<span class="lineNum">     666 </span>            :   // Equivalent to WriteRaw(str.data(), str.size()).
<span class="lineNum">     667 </span>            :   void WriteString(const string&amp; str);
<span class="lineNum">     668 </span>            :   // Like WriteString()  but writing directly to the target array.
<span class="lineNum">     669 </span>            :   static uint8* WriteStringToArray(const string&amp; str, uint8* target);
<span class="lineNum">     670 </span>            :   // Write the varint-encoded size of str followed by str.
<span class="lineNum">     671 </span>            :   static uint8* WriteStringWithSizeToArray(const string&amp; str, uint8* target);
<span class="lineNum">     672 </span>            : 
<span class="lineNum">     673 </span>            : 
<span class="lineNum">     674 </span>            :   // Instructs the CodedOutputStream to allow the underlying
<span class="lineNum">     675 </span>            :   // ZeroCopyOutputStream to hold pointers to the original structure instead of
<span class="lineNum">     676 </span>            :   // copying, if it supports it (i.e. output-&gt;AllowsAliasing() is true).  If the
<span class="lineNum">     677 </span>            :   // underlying stream does not support aliasing, then enabling it has no
<span class="lineNum">     678 </span>            :   // affect.  For now, this only affects the behavior of
<span class="lineNum">     679 </span>            :   // WriteRawMaybeAliased().
<span class="lineNum">     680 </span>            :   //
<span class="lineNum">     681 </span>            :   // NOTE: It is caller's responsibility to ensure that the chunk of memory
<span class="lineNum">     682 </span>            :   // remains live until all of the data has been consumed from the stream.
<span class="lineNum">     683 </span>            :   void EnableAliasing(bool enabled);
<span class="lineNum">     684 </span>            : 
<span class="lineNum">     685 </span>            :   // Write a 32-bit little-endian integer.
<span class="lineNum">     686 </span>            :   void WriteLittleEndian32(uint32 value);
<span class="lineNum">     687 </span>            :   // Like WriteLittleEndian32()  but writing directly to the target array.
<span class="lineNum">     688 </span>            :   static uint8* WriteLittleEndian32ToArray(uint32 value, uint8* target);
<span class="lineNum">     689 </span>            :   // Write a 64-bit little-endian integer.
<span class="lineNum">     690 </span>            :   void WriteLittleEndian64(uint64 value);
<span class="lineNum">     691 </span>            :   // Like WriteLittleEndian64()  but writing directly to the target array.
<span class="lineNum">     692 </span>            :   static uint8* WriteLittleEndian64ToArray(uint64 value, uint8* target);
<span class="lineNum">     693 </span>            : 
<span class="lineNum">     694 </span>            :   // Write an unsigned integer with Varint encoding.  Writing a 32-bit value
<span class="lineNum">     695 </span>            :   // is equivalent to casting it to uint64 and writing it as a 64-bit value,
<span class="lineNum">     696 </span>            :   // but may be more efficient.
<span class="lineNum">     697 </span>            :   void WriteVarint32(uint32 value);
<span class="lineNum">     698 </span>            :   // Like WriteVarint32()  but writing directly to the target array.
<span class="lineNum">     699 </span>            :   static uint8* WriteVarint32ToArray(uint32 value, uint8* target);
<span class="lineNum">     700 </span>            :   // Write an unsigned integer with Varint encoding.
<span class="lineNum">     701 </span>            :   void WriteVarint64(uint64 value);
<span class="lineNum">     702 </span>            :   // Like WriteVarint64()  but writing directly to the target array.
<span class="lineNum">     703 </span>            :   static uint8* WriteVarint64ToArray(uint64 value, uint8* target);
<span class="lineNum">     704 </span>            : 
<span class="lineNum">     705 </span>            :   // Equivalent to WriteVarint32() except when the value is negative,
<span class="lineNum">     706 </span>            :   // in which case it must be sign-extended to a full 10 bytes.
<span class="lineNum">     707 </span>            :   void WriteVarint32SignExtended(int32 value);
<span class="lineNum">     708 </span>            :   // Like WriteVarint32SignExtended()  but writing directly to the target array.
<span class="lineNum">     709 </span>            :   static uint8* WriteVarint32SignExtendedToArray(int32 value, uint8* target);
<span class="lineNum">     710 </span>            : 
<span class="lineNum">     711 </span>            :   // This is identical to WriteVarint32(), but optimized for writing tags.
<span class="lineNum">     712 </span>            :   // In particular, if the input is a compile-time constant, this method
<span class="lineNum">     713 </span>            :   // compiles down to a couple instructions.
<span class="lineNum">     714 </span>            :   // Always inline because otherwise the aformentioned optimization can't work,
<span class="lineNum">     715 </span>            :   // but GCC by default doesn't want to inline this.
<span class="lineNum">     716 </span>            :   void WriteTag(uint32 value);
<span class="lineNum">     717 </span>            :   // Like WriteTag()  but writing directly to the target array.
<span class="lineNum">     718 </span>            :   static uint8* WriteTagToArray(
<span class="lineNum">     719 </span>            :       uint32 value, uint8* target) GOOGLE_ATTRIBUTE_ALWAYS_INLINE;
<span class="lineNum">     720 </span>            : 
<span class="lineNum">     721 </span>            :   // Returns the number of bytes needed to encode the given value as a varint.
<span class="lineNum">     722 </span>            :   static int VarintSize32(uint32 value);
<span class="lineNum">     723 </span>            :   // Returns the number of bytes needed to encode the given value as a varint.
<span class="lineNum">     724 </span>            :   static int VarintSize64(uint64 value);
<span class="lineNum">     725 </span>            : 
<span class="lineNum">     726 </span>            :   // If negative, 10 bytes.  Otheriwse, same as VarintSize32().
<span class="lineNum">     727 </span>            :   static int VarintSize32SignExtended(int32 value);
<span class="lineNum">     728 </span>            : 
<span class="lineNum">     729 </span>            :   // Compile-time equivalent of VarintSize32().
<span class="lineNum">     730 </span>            :   template &lt;uint32 Value&gt;
<span class="lineNum">     731 </span>            :   struct StaticVarintSize32 {
<span class="lineNum">     732 </span>            :     static const int value =
<span class="lineNum">     733 </span>            :         (Value &lt; (1 &lt;&lt; 7))
<span class="lineNum">     734 </span>            :             ? 1
<span class="lineNum">     735 </span>            :             : (Value &lt; (1 &lt;&lt; 14))
<span class="lineNum">     736 </span>            :                 ? 2
<span class="lineNum">     737 </span>            :                 : (Value &lt; (1 &lt;&lt; 21))
<span class="lineNum">     738 </span>            :                     ? 3
<span class="lineNum">     739 </span>            :                     : (Value &lt; (1 &lt;&lt; 28))
<span class="lineNum">     740 </span>            :                         ? 4
<span class="lineNum">     741 </span>            :                         : 5;
<span class="lineNum">     742 </span>            :   };
<span class="lineNum">     743 </span>            : 
<span class="lineNum">     744 </span>            :   // Returns the total number of bytes written since this object was created.
<span class="lineNum">     745 </span>            :   inline int ByteCount() const;
<span class="lineNum">     746 </span>            : 
<span class="lineNum">     747 </span>            :   // Returns true if there was an underlying I/O error since this object was
<span class="lineNum">     748 </span>            :   // created.
<span class="lineNum">     749 </span>            :   bool HadError() const { return had_error_; }
<span class="lineNum">     750 </span>            : 
<span class="lineNum">     751 </span>            :  private:
<span class="lineNum">     752 </span>            :   GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(CodedOutputStream);
<span class="lineNum">     753 </span>            : 
<span class="lineNum">     754 </span>            :   ZeroCopyOutputStream* output_;
<span class="lineNum">     755 </span>            :   uint8* buffer_;
<span class="lineNum">     756 </span>            :   int buffer_size_;
<span class="lineNum">     757 </span>            :   int total_bytes_;  // Sum of sizes of all buffers seen so far.
<span class="lineNum">     758 </span>            :   bool had_error_;   // Whether an error occurred during output.
<span class="lineNum">     759 </span>            :   bool aliasing_enabled_;  // See EnableAliasing().
<span class="lineNum">     760 </span>            : 
<span class="lineNum">     761 </span>            :   // Advance the buffer by a given number of bytes.
<span class="lineNum">     762 </span>            :   void Advance(int amount);
<span class="lineNum">     763 </span>            : 
<span class="lineNum">     764 </span>            :   // Called when the buffer runs out to request more data.  Implies an
<span class="lineNum">     765 </span>            :   // Advance(buffer_size_).
<span class="lineNum">     766 </span>            :   bool Refresh();
<span class="lineNum">     767 </span>            : 
<span class="lineNum">     768 </span>            :   // Like WriteRaw() but may avoid copying if the underlying
<span class="lineNum">     769 </span>            :   // ZeroCopyOutputStream supports it.
<span class="lineNum">     770 </span>            :   void WriteAliasedRaw(const void* buffer, int size);
<span class="lineNum">     771 </span>            : 
<span class="lineNum">     772 </span>            :   static uint8* WriteVarint32FallbackToArray(uint32 value, uint8* target);
<span class="lineNum">     773 </span>            : 
<span class="lineNum">     774 </span>            :   // Always-inlined versions of WriteVarint* functions so that code can be
<span class="lineNum">     775 </span>            :   // reused, while still controlling size. For instance, WriteVarint32ToArray()
<span class="lineNum">     776 </span>            :   // should not directly call this: since it is inlined itself, doing so
<span class="lineNum">     777 </span>            :   // would greatly increase the size of generated code. Instead, it should call
<span class="lineNum">     778 </span>            :   // WriteVarint32FallbackToArray.  Meanwhile, WriteVarint32() is already
<span class="lineNum">     779 </span>            :   // out-of-line, so it should just invoke this directly to avoid any extra
<span class="lineNum">     780 </span>            :   // function call overhead.
<span class="lineNum">     781 </span>            :   static uint8* WriteVarint32FallbackToArrayInline(
<span class="lineNum">     782 </span>            :       uint32 value, uint8* target) GOOGLE_ATTRIBUTE_ALWAYS_INLINE;
<span class="lineNum">     783 </span>            :   static uint8* WriteVarint64ToArrayInline(
<span class="lineNum">     784 </span>            :       uint64 value, uint8* target) GOOGLE_ATTRIBUTE_ALWAYS_INLINE;
<span class="lineNum">     785 </span>            : 
<span class="lineNum">     786 </span>            :   static int VarintSize32Fallback(uint32 value);
<span class="lineNum">     787 </span>            : };
<span class="lineNum">     788 </span>            : 
<span class="lineNum">     789 </span>            : // inline methods ====================================================
<span class="lineNum">     790 </span>            : // The vast majority of varints are only one byte.  These inline
<a name="791"><span class="lineNum">     791 </span>            : // methods optimize for that case.</a>
<span class="lineNum">     792 </span>            : 
<span class="lineNum">     793 </span><span class="lineCov">    3402232 : inline bool CodedInputStream::ReadVarint32(uint32* value) {</span>
<span class="lineNum">     794 </span><span class="lineCov">    3402232 :   if (GOOGLE_PREDICT_TRUE(buffer_ &lt; buffer_end_) &amp;&amp; *buffer_ &lt; 0x80) {</span>
<span class="lineNum">     795 </span><span class="lineCov">    3402232 :     *value = *buffer_;</span>
<span class="lineNum">     796 </span>            :     Advance(1);
<span class="lineNum">     797 </span><span class="lineCov">    3402232 :     return true;</span>
<span class="lineNum">     798 </span>            :   } else {
<span class="lineNum">     799 </span><span class="lineNoCov">          0 :     return ReadVarint32Fallback(value);</span>
<span class="lineNum">     800 </span>            :   }
<a name="801"><span class="lineNum">     801 </span>            : }</a>
<span class="lineNum">     802 </span>            : 
<span class="lineNum">     803 </span><span class="lineNoCov">          0 : inline bool CodedInputStream::ReadVarint64(uint64* value) {</span>
<span class="lineNum">     804 </span><span class="lineNoCov">          0 :   if (GOOGLE_PREDICT_TRUE(buffer_ &lt; buffer_end_) &amp;&amp; *buffer_ &lt; 0x80) {</span>
<span class="lineNum">     805 </span><span class="lineNoCov">          0 :     *value = *buffer_;</span>
<span class="lineNum">     806 </span>            :     Advance(1);
<span class="lineNum">     807 </span><span class="lineNoCov">          0 :     return true;</span>
<span class="lineNum">     808 </span>            :   } else {
<span class="lineNum">     809 </span><span class="lineNoCov">          0 :     return ReadVarint64Fallback(value);</span>
<span class="lineNum">     810 </span>            :   }
<span class="lineNum">     811 </span>            : }
<span class="lineNum">     812 </span>            : 
<span class="lineNum">     813 </span>            : // static
<span class="lineNum">     814 </span>            : inline const uint8* CodedInputStream::ReadLittleEndian32FromArray(
<span class="lineNum">     815 </span>            :     const uint8* buffer,
<span class="lineNum">     816 </span>            :     uint32* value) {
<span class="lineNum">     817 </span>            : #if defined(PROTOBUF_LITTLE_ENDIAN)
<span class="lineNum">     818 </span>            :   memcpy(value, buffer, sizeof(*value));
<span class="lineNum">     819 </span><span class="lineNoCov">          0 :   return buffer + sizeof(*value);</span>
<span class="lineNum">     820 </span>            : #else
<span class="lineNum">     821 </span>            :   *value = (static_cast&lt;uint32&gt;(buffer[0])      ) |
<span class="lineNum">     822 </span>            :            (static_cast&lt;uint32&gt;(buffer[1]) &lt;&lt;  8) |
<span class="lineNum">     823 </span>            :            (static_cast&lt;uint32&gt;(buffer[2]) &lt;&lt; 16) |
<span class="lineNum">     824 </span>            :            (static_cast&lt;uint32&gt;(buffer[3]) &lt;&lt; 24);
<span class="lineNum">     825 </span>            :   return buffer + sizeof(*value);
<span class="lineNum">     826 </span>            : #endif
<span class="lineNum">     827 </span>            : }
<span class="lineNum">     828 </span>            : // static
<span class="lineNum">     829 </span>            : inline const uint8* CodedInputStream::ReadLittleEndian64FromArray(
<span class="lineNum">     830 </span>            :     const uint8* buffer,
<span class="lineNum">     831 </span>            :     uint64* value) {
<span class="lineNum">     832 </span>            : #if defined(PROTOBUF_LITTLE_ENDIAN)
<span class="lineNum">     833 </span>            :   memcpy(value, buffer, sizeof(*value));
<span class="lineNum">     834 </span><span class="lineNoCov">          0 :   return buffer + sizeof(*value);</span>
<span class="lineNum">     835 </span>            : #else
<span class="lineNum">     836 </span>            :   uint32 part0 = (static_cast&lt;uint32&gt;(buffer[0])      ) |
<span class="lineNum">     837 </span>            :                  (static_cast&lt;uint32&gt;(buffer[1]) &lt;&lt;  8) |
<span class="lineNum">     838 </span>            :                  (static_cast&lt;uint32&gt;(buffer[2]) &lt;&lt; 16) |
<span class="lineNum">     839 </span>            :                  (static_cast&lt;uint32&gt;(buffer[3]) &lt;&lt; 24);
<span class="lineNum">     840 </span>            :   uint32 part1 = (static_cast&lt;uint32&gt;(buffer[4])      ) |
<span class="lineNum">     841 </span>            :                  (static_cast&lt;uint32&gt;(buffer[5]) &lt;&lt;  8) |
<span class="lineNum">     842 </span>            :                  (static_cast&lt;uint32&gt;(buffer[6]) &lt;&lt; 16) |
<span class="lineNum">     843 </span>            :                  (static_cast&lt;uint32&gt;(buffer[7]) &lt;&lt; 24);
<span class="lineNum">     844 </span>            :   *value = static_cast&lt;uint64&gt;(part0) |
<span class="lineNum">     845 </span>            :           (static_cast&lt;uint64&gt;(part1) &lt;&lt; 32);
<span class="lineNum">     846 </span>            :   return buffer + sizeof(*value);
<span class="lineNum">     847 </span>            : #endif
<a name="848"><span class="lineNum">     848 </span>            : }</a>
<span class="lineNum">     849 </span>            : 
<span class="lineNum">     850 </span><span class="lineNoCov">          0 : inline bool CodedInputStream::ReadLittleEndian32(uint32* value) {</span>
<span class="lineNum">     851 </span>            : #if defined(PROTOBUF_LITTLE_ENDIAN)
<span class="lineNum">     852 </span><span class="lineNoCov">          0 :   if (GOOGLE_PREDICT_TRUE(BufferSize() &gt;= static_cast&lt;int&gt;(sizeof(*value)))) {</span>
<span class="lineNum">     853 </span>            :     memcpy(value, buffer_, sizeof(*value));
<span class="lineNum">     854 </span>            :     Advance(sizeof(*value));
<span class="lineNum">     855 </span><span class="lineNoCov">          0 :     return true;</span>
<span class="lineNum">     856 </span>            :   } else {
<span class="lineNum">     857 </span><span class="lineNoCov">          0 :     return ReadLittleEndian32Fallback(value);</span>
<span class="lineNum">     858 </span>            :   }
<span class="lineNum">     859 </span>            : #else
<span class="lineNum">     860 </span>            :   return ReadLittleEndian32Fallback(value);
<span class="lineNum">     861 </span>            : #endif
<a name="862"><span class="lineNum">     862 </span>            : }</a>
<span class="lineNum">     863 </span>            : 
<span class="lineNum">     864 </span><span class="lineNoCov">          0 : inline bool CodedInputStream::ReadLittleEndian64(uint64* value) {</span>
<span class="lineNum">     865 </span>            : #if defined(PROTOBUF_LITTLE_ENDIAN)
<span class="lineNum">     866 </span><span class="lineNoCov">          0 :   if (GOOGLE_PREDICT_TRUE(BufferSize() &gt;= static_cast&lt;int&gt;(sizeof(*value)))) {</span>
<span class="lineNum">     867 </span>            :     memcpy(value, buffer_, sizeof(*value));
<span class="lineNum">     868 </span>            :     Advance(sizeof(*value));
<span class="lineNum">     869 </span><span class="lineNoCov">          0 :     return true;</span>
<span class="lineNum">     870 </span>            :   } else {
<span class="lineNum">     871 </span><span class="lineNoCov">          0 :     return ReadLittleEndian64Fallback(value);</span>
<span class="lineNum">     872 </span>            :   }
<span class="lineNum">     873 </span>            : #else
<span class="lineNum">     874 </span>            :   return ReadLittleEndian64Fallback(value);
<span class="lineNum">     875 </span>            : #endif
<span class="lineNum">     876 </span>            : }
<span class="lineNum">     877 </span>            : 
<span class="lineNum">     878 </span>            : inline uint32 CodedInputStream::ReadTag() {
<span class="lineNum">     879 </span>            :   if (GOOGLE_PREDICT_TRUE(buffer_ &lt; buffer_end_) &amp;&amp; buffer_[0] &lt; 0x80) {
<span class="lineNum">     880 </span>            :     last_tag_ = buffer_[0];
<span class="lineNum">     881 </span>            :     Advance(1);
<span class="lineNum">     882 </span>            :     return last_tag_;
<span class="lineNum">     883 </span>            :   } else {
<span class="lineNum">     884 </span>            :     last_tag_ = ReadTagFallback();
<span class="lineNum">     885 </span>            :     return last_tag_;
<span class="lineNum">     886 </span>            :   }
<span class="lineNum">     887 </span>            : }
<span class="lineNum">     888 </span>            : 
<span class="lineNum">     889 </span>            : inline std::pair&lt;uint32, bool&gt; CodedInputStream::ReadTagWithCutoff(
<span class="lineNum">     890 </span>            :     uint32 cutoff) {
<span class="lineNum">     891 </span>            :   // In performance-sensitive code we can expect cutoff to be a compile-time
<span class="lineNum">     892 </span>            :   // constant, and things like &quot;cutoff &gt;= kMax1ByteVarint&quot; to be evaluated at
<span class="lineNum">     893 </span>            :   // compile time.
<span class="lineNum">     894 </span><span class="lineCov">    1701116 :   if (GOOGLE_PREDICT_TRUE(buffer_ &lt; buffer_end_)) {</span>
<span class="lineNum">     895 </span>            :     // Hot case: buffer_ non_empty, buffer_[0] in [1, 128).
<span class="lineNum">     896 </span>            :     // TODO(gpike): Is it worth rearranging this? E.g., if the number of fields
<span class="lineNum">     897 </span>            :     // is large enough then is it better to check for the two-byte case first?
<span class="lineNum">     898 </span><span class="lineCov">     850558 :     if (static_cast&lt;int8&gt;(buffer_[0]) &gt; 0) {</span>
<span class="lineNum">     899 </span>            :       const uint32 kMax1ByteVarint = 0x7f;
<span class="lineNum">     900 </span><span class="lineCov">     850558 :       uint32 tag = last_tag_ = buffer_[0];</span>
<span class="lineNum">     901 </span>            :       Advance(1);
<span class="lineNum">     902 </span><span class="lineNoCov">          0 :       return make_pair(tag, cutoff &gt;= kMax1ByteVarint || tag &lt;= cutoff);</span>
<span class="lineNum">     903 </span>            :     }
<span class="lineNum">     904 </span>            :     // Other hot case: cutoff &gt;= 0x80, buffer_ has at least two bytes available,
<span class="lineNum">     905 </span>            :     // and tag is two bytes.  The latter is tested by bitwise-and-not of the
<span class="lineNum">     906 </span>            :     // first byte and the second byte.
<span class="lineNum">     907 </span><span class="lineNoCov">          0 :     if (cutoff &gt;= 0x80 &amp;&amp;</span>
<span class="lineNum">     908 </span><span class="lineNoCov">          0 :         GOOGLE_PREDICT_TRUE(buffer_ + 1 &lt; buffer_end_) &amp;&amp;</span>
<span class="lineNum">     909 </span><span class="lineNoCov">          0 :         GOOGLE_PREDICT_TRUE((buffer_[0] &amp; ~buffer_[1]) &gt;= 0x80)) {</span>
<span class="lineNum">     910 </span>            :       const uint32 kMax2ByteVarint = (0x7f &lt;&lt; 7) + 0x7f;
<span class="lineNum">     911 </span><span class="lineNoCov">          0 :       uint32 tag = last_tag_ = (1u &lt;&lt; 7) * buffer_[1] + (buffer_[0] - 0x80);</span>
<span class="lineNum">     912 </span>            :       Advance(2);
<span class="lineNum">     913 </span>            :       // It might make sense to test for tag == 0 now, but it is so rare that
<span class="lineNum">     914 </span>            :       // that we don't bother.  A varint-encoded 0 should be one byte unless
<span class="lineNum">     915 </span>            :       // the encoder lost its mind.  The second part of the return value of
<span class="lineNum">     916 </span>            :       // this function is allowed to be either true or false if the tag is 0,
<span class="lineNum">     917 </span>            :       // so we don't have to check for tag == 0.  We may need to check whether
<span class="lineNum">     918 </span>            :       // it exceeds cutoff.
<span class="lineNum">     919 </span>            :       bool at_or_below_cutoff = cutoff &gt;= kMax2ByteVarint || tag &lt;= cutoff;
<span class="lineNum">     920 </span>            :       return make_pair(tag, at_or_below_cutoff);
<span class="lineNum">     921 </span>            :     }
<span class="lineNum">     922 </span>            :   }
<span class="lineNum">     923 </span>            :   // Slow path
<span class="lineNum">     924 </span><span class="lineCov">     850558 :   last_tag_ = ReadTagFallback();</span>
<span class="lineNum">     925 </span><span class="lineCov">     850558 :   return make_pair(last_tag_, static_cast&lt;uint32&gt;(last_tag_ - 1) &lt; cutoff);</span>
<span class="lineNum">     926 </span>            : }
<span class="lineNum">     927 </span>            : 
<span class="lineNum">     928 </span>            : inline bool CodedInputStream::LastTagWas(uint32 expected) {
<span class="lineNum">     929 </span>            :   return last_tag_ == expected;
<span class="lineNum">     930 </span>            : }
<span class="lineNum">     931 </span>            : 
<span class="lineNum">     932 </span>            : inline bool CodedInputStream::ConsumedEntireMessage() {
<span class="lineNum">     933 </span>            :   return legitimate_message_end_;
<span class="lineNum">     934 </span>            : }
<span class="lineNum">     935 </span>            : 
<span class="lineNum">     936 </span>            : inline bool CodedInputStream::ExpectTag(uint32 expected) {
<span class="lineNum">     937 </span><span class="lineNoCov">          0 :   if (expected &lt; (1 &lt;&lt; 7)) {</span>
<span class="lineNum">     938 </span><span class="lineCov">    4252790 :     if (GOOGLE_PREDICT_TRUE(buffer_ &lt; buffer_end_) &amp;&amp; buffer_[0] == expected) {</span>
<span class="lineNum">     939 </span>            :       Advance(1);
<span class="lineNum">     940 </span>            :       return true;
<span class="lineNum">     941 </span>            :     } else {
<span class="lineNum">     942 </span>            :       return false;
<span class="lineNum">     943 </span>            :     }
<span class="lineNum">     944 </span><span class="lineNoCov">          0 :   } else if (expected &lt; (1 &lt;&lt; 14)) {</span>
<span class="lineNum">     945 </span><span class="lineNoCov">          0 :     if (GOOGLE_PREDICT_TRUE(BufferSize() &gt;= 2) &amp;&amp;</span>
<span class="lineNum">     946 </span><span class="lineNoCov">          0 :         buffer_[0] == static_cast&lt;uint8&gt;(expected | 0x80) &amp;&amp;</span>
<span class="lineNum">     947 </span><span class="lineNoCov">          0 :         buffer_[1] == static_cast&lt;uint8&gt;(expected &gt;&gt; 7)) {</span>
<span class="lineNum">     948 </span>            :       Advance(2);
<span class="lineNum">     949 </span>            :       return true;
<span class="lineNum">     950 </span>            :     } else {
<span class="lineNum">     951 </span>            :       return false;
<span class="lineNum">     952 </span>            :     }
<span class="lineNum">     953 </span>            :   } else {
<span class="lineNum">     954 </span>            :     // Don't bother optimizing for larger values.
<span class="lineNum">     955 </span>            :     return false;
<span class="lineNum">     956 </span>            :   }
<span class="lineNum">     957 </span>            : }
<span class="lineNum">     958 </span>            : 
<span class="lineNum">     959 </span>            : inline const uint8* CodedInputStream::ExpectTagFromArray(
<span class="lineNum">     960 </span>            :     const uint8* buffer, uint32 expected) {
<span class="lineNum">     961 </span><span class="lineNoCov">          0 :   if (expected &lt; (1 &lt;&lt; 7)) {</span>
<span class="lineNum">     962 </span><span class="lineNoCov">          0 :     if (buffer[0] == expected) {</span>
<span class="lineNum">     963 </span><span class="lineNoCov">          0 :       return buffer + 1;</span>
<span class="lineNum">     964 </span>            :     }
<span class="lineNum">     965 </span><span class="lineNoCov">          0 :   } else if (expected &lt; (1 &lt;&lt; 14)) {</span>
<span class="lineNum">     966 </span><span class="lineNoCov">          0 :     if (buffer[0] == static_cast&lt;uint8&gt;(expected | 0x80) &amp;&amp;</span>
<span class="lineNum">     967 </span><span class="lineNoCov">          0 :         buffer[1] == static_cast&lt;uint8&gt;(expected &gt;&gt; 7)) {</span>
<span class="lineNum">     968 </span><span class="lineNoCov">          0 :       return buffer + 2;</span>
<span class="lineNum">     969 </span>            :     }
<span class="lineNum">     970 </span>            :   }
<span class="lineNum">     971 </span>            :   return NULL;
<span class="lineNum">     972 </span>            : }
<span class="lineNum">     973 </span>            : 
<span class="lineNum">     974 </span>            : inline void CodedInputStream::GetDirectBufferPointerInline(const void** data,
<span class="lineNum">     975 </span>            :                                                            int* size) {
<span class="lineNum">     976 </span><span class="lineNoCov">          0 :   *data = buffer_;</span>
<span class="lineNum">     977 </span><span class="lineNoCov">          0 :   *size = buffer_end_ - buffer_;</span>
<span class="lineNum">     978 </span>            : }
<span class="lineNum">     979 </span>            : 
<span class="lineNum">     980 </span>            : inline bool CodedInputStream::ExpectAtEnd() {
<span class="lineNum">     981 </span>            :   // If we are at a limit we know no more bytes can be read.  Otherwise, it's
<span class="lineNum">     982 </span>            :   // hard to say without calling Refresh(), and we'd rather not do that.
<span class="lineNum">     983 </span>            : 
<span class="lineNum">     984 </span><span class="lineNoCov">          0 :   if (buffer_ == buffer_end_ &amp;&amp;</span>
<span class="lineNum">     985 </span><span class="lineNoCov">          0 :       ((buffer_size_after_limit_ != 0) ||</span>
<span class="lineNum">     986 </span><span class="lineNoCov">          0 :        (total_bytes_read_ == current_limit_))) {</span>
<span class="lineNum">     987 </span><span class="lineNoCov">          0 :     last_tag_ = 0;                   // Pretend we called ReadTag()...</span>
<span class="lineNum">     988 </span><span class="lineNoCov">          0 :     legitimate_message_end_ = true;  // ... and it hit EOF.</span>
<span class="lineNum">     989 </span>            :     return true;
<span class="lineNum">     990 </span>            :   } else {
<span class="lineNum">     991 </span>            :     return false;
<span class="lineNum">     992 </span>            :   }
<span class="lineNum">     993 </span>            : }
<span class="lineNum">     994 </span>            : 
<span class="lineNum">     995 </span>            : inline int CodedInputStream::CurrentPosition() const {
<span class="lineNum">     996 </span>            :   return total_bytes_read_ - (BufferSize() + buffer_size_after_limit_);
<span class="lineNum">     997 </span>            : }
<span class="lineNum">     998 </span>            : 
<span class="lineNum">     999 </span>            : inline uint8* CodedOutputStream::GetDirectBufferForNBytesAndAdvance(int size) {
<span class="lineNum">    1000 </span>            :   if (buffer_size_ &lt; size) {
<span class="lineNum">    1001 </span>            :     return NULL;
<span class="lineNum">    1002 </span>            :   } else {
<span class="lineNum">    1003 </span>            :     uint8* result = buffer_;
<span class="lineNum">    1004 </span>            :     Advance(size);
<span class="lineNum">    1005 </span>            :     return result;
<span class="lineNum">    1006 </span>            :   }
<span class="lineNum">    1007 </span>            : }
<span class="lineNum">    1008 </span>            : 
<span class="lineNum">    1009 </span>            : inline uint8* CodedOutputStream::WriteVarint32ToArray(uint32 value,
<span class="lineNum">    1010 </span>            :                                                         uint8* target) {
<span class="lineNum">    1011 </span><span class="lineCov">        146 :   if (value &lt; 0x80) {</span>
<span class="lineNum">    1012 </span><span class="lineCov">        134 :     *target = value;</span>
<span class="lineNum">    1013 </span><span class="lineCov">        134 :     return target + 1;</span>
<span class="lineNum">    1014 </span>            :   } else {
<span class="lineNum">    1015 </span><span class="lineCov">         12 :     return WriteVarint32FallbackToArray(value, target);</span>
<span class="lineNum">    1016 </span>            :   }
<span class="lineNum">    1017 </span>            : }
<span class="lineNum">    1018 </span>            : 
<span class="lineNum">    1019 </span>            : inline void CodedOutputStream::WriteVarint32SignExtended(int32 value) {
<span class="lineNum">    1020 </span>            :   if (value &lt; 0) {
<span class="lineNum">    1021 </span>            :     WriteVarint64(static_cast&lt;uint64&gt;(value));
<span class="lineNum">    1022 </span>            :   } else {
<span class="lineNum">    1023 </span>            :     WriteVarint32(static_cast&lt;uint32&gt;(value));
<span class="lineNum">    1024 </span>            :   }
<a name="1025"><span class="lineNum">    1025 </span>            : }</a>
<span class="lineNum">    1026 </span>            : 
<span class="lineNum">    1027 </span><span class="lineCov">         20 : inline uint8* CodedOutputStream::WriteVarint32SignExtendedToArray(</span>
<span class="lineNum">    1028 </span>            :     int32 value, uint8* target) {
<span class="lineNum">    1029 </span><span class="lineCov">         20 :   if (value &lt; 0) {</span>
<span class="lineNum">    1030 </span><span class="lineNoCov">          0 :     return WriteVarint64ToArray(static_cast&lt;uint64&gt;(value), target);</span>
<span class="lineNum">    1031 </span>            :   } else {
<span class="lineNum">    1032 </span><span class="lineCov">         40 :     return WriteVarint32ToArray(static_cast&lt;uint32&gt;(value), target);</span>
<span class="lineNum">    1033 </span>            :   }
<span class="lineNum">    1034 </span>            : }
<span class="lineNum">    1035 </span>            : 
<span class="lineNum">    1036 </span>            : inline uint8* CodedOutputStream::WriteLittleEndian32ToArray(uint32 value,
<span class="lineNum">    1037 </span>            :                                                             uint8* target) {
<span class="lineNum">    1038 </span>            : #if defined(PROTOBUF_LITTLE_ENDIAN)
<span class="lineNum">    1039 </span>            :   memcpy(target, &amp;value, sizeof(value));
<span class="lineNum">    1040 </span>            : #else
<span class="lineNum">    1041 </span>            :   target[0] = static_cast&lt;uint8&gt;(value);
<span class="lineNum">    1042 </span>            :   target[1] = static_cast&lt;uint8&gt;(value &gt;&gt;  8);
<span class="lineNum">    1043 </span>            :   target[2] = static_cast&lt;uint8&gt;(value &gt;&gt; 16);
<span class="lineNum">    1044 </span>            :   target[3] = static_cast&lt;uint8&gt;(value &gt;&gt; 24);
<span class="lineNum">    1045 </span>            : #endif
<span class="lineNum">    1046 </span><span class="lineCov">       2340 :   return target + sizeof(value);</span>
<span class="lineNum">    1047 </span>            : }
<span class="lineNum">    1048 </span>            : 
<span class="lineNum">    1049 </span>            : inline uint8* CodedOutputStream::WriteLittleEndian64ToArray(uint64 value,
<span class="lineNum">    1050 </span>            :                                                             uint8* target) {
<span class="lineNum">    1051 </span>            : #if defined(PROTOBUF_LITTLE_ENDIAN)
<span class="lineNum">    1052 </span>            :   memcpy(target, &amp;value, sizeof(value));
<span class="lineNum">    1053 </span>            : #else
<span class="lineNum">    1054 </span>            :   uint32 part0 = static_cast&lt;uint32&gt;(value);
<span class="lineNum">    1055 </span>            :   uint32 part1 = static_cast&lt;uint32&gt;(value &gt;&gt; 32);
<span class="lineNum">    1056 </span>            : 
<span class="lineNum">    1057 </span>            :   target[0] = static_cast&lt;uint8&gt;(part0);
<span class="lineNum">    1058 </span>            :   target[1] = static_cast&lt;uint8&gt;(part0 &gt;&gt;  8);
<span class="lineNum">    1059 </span>            :   target[2] = static_cast&lt;uint8&gt;(part0 &gt;&gt; 16);
<span class="lineNum">    1060 </span>            :   target[3] = static_cast&lt;uint8&gt;(part0 &gt;&gt; 24);
<span class="lineNum">    1061 </span>            :   target[4] = static_cast&lt;uint8&gt;(part1);
<span class="lineNum">    1062 </span>            :   target[5] = static_cast&lt;uint8&gt;(part1 &gt;&gt;  8);
<span class="lineNum">    1063 </span>            :   target[6] = static_cast&lt;uint8&gt;(part1 &gt;&gt; 16);
<span class="lineNum">    1064 </span>            :   target[7] = static_cast&lt;uint8&gt;(part1 &gt;&gt; 24);
<span class="lineNum">    1065 </span>            : #endif
<span class="lineNum">    1066 </span><span class="lineNoCov">          0 :   return target + sizeof(value);</span>
<span class="lineNum">    1067 </span>            : }
<span class="lineNum">    1068 </span>            : 
<span class="lineNum">    1069 </span>            : inline void CodedOutputStream::WriteTag(uint32 value) {
<span class="lineNum">    1070 </span><span class="lineCov">         16 :   WriteVarint32(value);</span>
<span class="lineNum">    1071 </span>            : }
<span class="lineNum">    1072 </span>            : 
<span class="lineNum">    1073 </span>            : inline uint8* CodedOutputStream::WriteTagToArray(
<span class="lineNum">    1074 </span>            :     uint32 value, uint8* target) {
<span class="lineNum">    1075 </span>            :   if (value &lt; (1 &lt;&lt; 7)) {
<span class="lineNum">    1076 </span><span class="lineCov">        224 :     target[0] = value;</span>
<span class="lineNum">    1077 </span><span class="lineCov">        224 :     return target + 1;</span>
<span class="lineNum">    1078 </span>            :   } else if (value &lt; (1 &lt;&lt; 14)) {
<span class="lineNum">    1079 </span><span class="lineCov">         10 :     target[0] = static_cast&lt;uint8&gt;(value | 0x80);</span>
<span class="lineNum">    1080 </span><span class="lineCov">         10 :     target[1] = static_cast&lt;uint8&gt;(value &gt;&gt; 7);</span>
<span class="lineNum">    1081 </span><span class="lineCov">         10 :     return target + 2;</span>
<span class="lineNum">    1082 </span>            :   } else {
<span class="lineNum">    1083 </span>            :     return WriteVarint32FallbackToArray(value, target);
<span class="lineNum">    1084 </span>            :   }
<span class="lineNum">    1085 </span>            : }
<span class="lineNum">    1086 </span>            : 
<span class="lineNum">    1087 </span>            : inline int CodedOutputStream::VarintSize32(uint32 value) {
<span class="lineNum">    1088 </span><span class="lineCov">        348 :   if (value &lt; (1 &lt;&lt; 7)) {</span>
<span class="lineNum">    1089 </span>            :     return 1;
<span class="lineNum">    1090 </span>            :   } else  {
<span class="lineNum">    1091 </span><span class="lineCov">         60 :     return VarintSize32Fallback(value);</span>
<span class="lineNum">    1092 </span>            :   }
<span class="lineNum">    1093 </span>            : }
<span class="lineNum">    1094 </span>            : 
<span class="lineNum">    1095 </span>            : inline int CodedOutputStream::VarintSize32SignExtended(int32 value) {
<span class="lineNum">    1096 </span><span class="lineCov">         94 :   if (value &lt; 0) {</span>
<span class="lineNum">    1097 </span>            :     return 10;     // TODO(kenton):  Make this a symbolic constant.
<span class="lineNum">    1098 </span>            :   } else {
<span class="lineNum">    1099 </span><span class="lineCov">         68 :     return VarintSize32(static_cast&lt;uint32&gt;(value));</span>
<span class="lineNum">    1100 </span>            :   }
<span class="lineNum">    1101 </span>            : }
<span class="lineNum">    1102 </span>            : 
<span class="lineNum">    1103 </span>            : inline void CodedOutputStream::WriteString(const string&amp; str) {
<span class="lineNum">    1104 </span>            :   WriteRaw(str.data(), static_cast&lt;int&gt;(str.size()));
<span class="lineNum">    1105 </span>            : }
<span class="lineNum">    1106 </span>            : 
<span class="lineNum">    1107 </span>            : inline void CodedOutputStream::WriteRawMaybeAliased(
<span class="lineNum">    1108 </span>            :     const void* data, int size) {
<span class="lineNum">    1109 </span>            :   if (aliasing_enabled_) {
<span class="lineNum">    1110 </span>            :     WriteAliasedRaw(data, size);
<span class="lineNum">    1111 </span>            :   } else {
<span class="lineNum">    1112 </span>            :     WriteRaw(data, size);
<span class="lineNum">    1113 </span>            :   }
<span class="lineNum">    1114 </span>            : }
<span class="lineNum">    1115 </span>            : 
<span class="lineNum">    1116 </span>            : inline uint8* CodedOutputStream::WriteStringToArray(
<span class="lineNum">    1117 </span>            :     const string&amp; str, uint8* target) {
<span class="lineNum">    1118 </span>            :   return WriteRawToArray(str.data(), static_cast&lt;int&gt;(str.size()), target);
<span class="lineNum">    1119 </span>            : }
<span class="lineNum">    1120 </span>            : 
<span class="lineNum">    1121 </span>            : inline int CodedOutputStream::ByteCount() const {
<span class="lineNum">    1122 </span>            :   return total_bytes_ - buffer_size_;
<span class="lineNum">    1123 </span>            : }
<span class="lineNum">    1124 </span>            : 
<span class="lineNum">    1125 </span>            : inline void CodedInputStream::Advance(int amount) {
<span class="lineNum">    1126 </span><span class="lineCov">    7655022 :   buffer_ += amount;</span>
<span class="lineNum">    1127 </span>            : }
<span class="lineNum">    1128 </span>            : 
<span class="lineNum">    1129 </span>            : inline void CodedOutputStream::Advance(int amount) {
<span class="lineNum">    1130 </span>            :   buffer_ += amount;
<span class="lineNum">    1131 </span>            :   buffer_size_ -= amount;
<span class="lineNum">    1132 </span>            : }
<span class="lineNum">    1133 </span>            : 
<span class="lineNum">    1134 </span>            : inline void CodedInputStream::SetRecursionLimit(int limit) {
<span class="lineNum">    1135 </span>            :   recursion_limit_ = limit;
<span class="lineNum">    1136 </span>            : }
<span class="lineNum">    1137 </span>            : 
<span class="lineNum">    1138 </span>            : inline bool CodedInputStream::IncrementRecursionDepth() {
<span class="lineNum">    1139 </span><span class="lineNoCov">          0 :   ++recursion_depth_;</span>
<span class="lineNum">    1140 </span>            :   return recursion_depth_ &lt;= recursion_limit_;
<span class="lineNum">    1141 </span>            : }
<span class="lineNum">    1142 </span>            : 
<span class="lineNum">    1143 </span>            : inline void CodedInputStream::DecrementRecursionDepth() {
<span class="lineNum">    1144 </span><span class="lineNoCov">          0 :   if (recursion_depth_ &gt; 0) --recursion_depth_;</span>
<span class="lineNum">    1145 </span>            : }
<span class="lineNum">    1146 </span>            : 
<span class="lineNum">    1147 </span>            : inline void CodedInputStream::SetExtensionRegistry(const DescriptorPool* pool,
<span class="lineNum">    1148 </span>            :                                                    MessageFactory* factory) {
<span class="lineNum">    1149 </span>            :   extension_pool_ = pool;
<span class="lineNum">    1150 </span>            :   extension_factory_ = factory;
<span class="lineNum">    1151 </span>            : }
<span class="lineNum">    1152 </span>            : 
<span class="lineNum">    1153 </span>            : inline const DescriptorPool* CodedInputStream::GetExtensionPool() {
<span class="lineNum">    1154 </span>            :   return extension_pool_;
<span class="lineNum">    1155 </span>            : }
<span class="lineNum">    1156 </span>            : 
<span class="lineNum">    1157 </span>            : inline MessageFactory* CodedInputStream::GetExtensionFactory() {
<span class="lineNum">    1158 </span>            :   return extension_factory_;
<span class="lineNum">    1159 </span>            : }
<span class="lineNum">    1160 </span>            : 
<span class="lineNum">    1161 </span>            : inline int CodedInputStream::BufferSize() const {
<span class="lineNum">    1162 </span><span class="lineNoCov">          0 :   return buffer_end_ - buffer_;</span>
<a name="1163"><span class="lineNum">    1163 </span>            : }</a>
<span class="lineNum">    1164 </span>            : 
<span class="lineNum">    1165 </span><span class="lineNoCov">          0 : inline CodedInputStream::CodedInputStream(ZeroCopyInputStream* input)</span>
<span class="lineNum">    1166 </span>            :   : input_(input),
<span class="lineNum">    1167 </span>            :     buffer_(NULL),
<span class="lineNum">    1168 </span>            :     buffer_end_(NULL),
<span class="lineNum">    1169 </span>            :     total_bytes_read_(0),
<span class="lineNum">    1170 </span>            :     overflow_bytes_(0),
<span class="lineNum">    1171 </span>            :     last_tag_(0),
<span class="lineNum">    1172 </span>            :     legitimate_message_end_(false),
<span class="lineNum">    1173 </span>            :     aliasing_enabled_(false),
<span class="lineNum">    1174 </span>            :     current_limit_(kint32max),
<span class="lineNum">    1175 </span>            :     buffer_size_after_limit_(0),
<span class="lineNum">    1176 </span>            :     total_bytes_limit_(kDefaultTotalBytesLimit),
<span class="lineNum">    1177 </span>            :     total_bytes_warning_threshold_(kDefaultTotalBytesWarningThreshold),
<span class="lineNum">    1178 </span>            :     recursion_depth_(0),
<span class="lineNum">    1179 </span>            :     recursion_limit_(default_recursion_limit_),
<span class="lineNum">    1180 </span>            :     extension_pool_(NULL),
<span class="lineNum">    1181 </span><span class="lineNoCov">          0 :     extension_factory_(NULL) {</span>
<span class="lineNum">    1182 </span>            :   // Eagerly Refresh() so buffer space is immediately available.
<span class="lineNum">    1183 </span><span class="lineNoCov">          0 :   Refresh();</span>
<span class="lineNum">    1184 </span><span class="lineNoCov">          0 : }</span>
<span class="lineNum">    1185 </span>            : 
<span class="lineNum">    1186 </span>            : inline CodedInputStream::CodedInputStream(const uint8* buffer, int size)
<span class="lineNum">    1187 </span>            :   : input_(NULL),
<span class="lineNum">    1188 </span>            :     buffer_(buffer),
<span class="lineNum">    1189 </span>            :     buffer_end_(buffer + size),
<span class="lineNum">    1190 </span>            :     total_bytes_read_(size),
<span class="lineNum">    1191 </span>            :     overflow_bytes_(0),
<span class="lineNum">    1192 </span>            :     last_tag_(0),
<span class="lineNum">    1193 </span>            :     legitimate_message_end_(false),
<span class="lineNum">    1194 </span>            :     aliasing_enabled_(false),
<span class="lineNum">    1195 </span>            :     current_limit_(size),
<span class="lineNum">    1196 </span>            :     buffer_size_after_limit_(0),
<span class="lineNum">    1197 </span>            :     total_bytes_limit_(kDefaultTotalBytesLimit),
<span class="lineNum">    1198 </span>            :     total_bytes_warning_threshold_(kDefaultTotalBytesWarningThreshold),
<span class="lineNum">    1199 </span>            :     recursion_depth_(0),
<span class="lineNum">    1200 </span>            :     recursion_limit_(default_recursion_limit_),
<span class="lineNum">    1201 </span>            :     extension_pool_(NULL),
<span class="lineNum">    1202 </span>            :     extension_factory_(NULL) {
<span class="lineNum">    1203 </span>            :   // Note that setting current_limit_ == size is important to prevent some
<span class="lineNum">    1204 </span>            :   // code paths from trying to access input_ and segfaulting.
<span class="lineNum">    1205 </span>            : }
<span class="lineNum">    1206 </span>            : 
<span class="lineNum">    1207 </span>            : inline bool CodedInputStream::IsFlat() const {
<span class="lineNum">    1208 </span>            :   return input_ == NULL;
<span class="lineNum">    1209 </span>            : }
<span class="lineNum">    1210 </span>            : 
<span class="lineNum">    1211 </span>            : }  // namespace io
<span class="lineNum">    1212 </span>            : }  // namespace protobuf
<span class="lineNum">    1213 </span>            : 
<span class="lineNum">    1214 </span>            : 
<span class="lineNum">    1215 </span>            : #if defined(_MSC_VER) &amp;&amp; _MSC_VER &gt;= 1300
<span class="lineNum">    1216 </span>            :   #pragma runtime_checks(&quot;c&quot;, restore)
<span class="lineNum">    1217 </span>            : #endif  // _MSC_VER
<span class="lineNum">    1218 </span>            : 
<span class="lineNum">    1219 </span>            : }  // namespace google
<span class="lineNum">    1220 </span>            : #endif  // GOOGLE_PROTOBUF_IO_CODED_STREAM_H__
</pre>
      </td>
    </tr>
  </table>
  <br>

  <table width="100%" border=0 cellspacing=0 cellpadding=0>
    <tr><td class="ruler"><img src="../../../../../glass.png" width=3 height=3 alt=""></td></tr>
    <tr><td class="versionInfo">Generated by: <a href="http://ltp.sourceforge.net/coverage/lcov.php" target="_parent">LCOV version 1.12</a></td></tr>
  </table>
  <br>

</body>
</html>
